README
@nuskin/ns-xdcookies
This library is extended from the original cross-domain cookie library (https://github.com/contently/xdomain-cookies).
We enhanced the library as follows:
- 'SameSite' to the cookies so that it works for modern browsers (especially Chrome) which forbids the third party cookies.
- Removed a script error in the browser when data is null.
- Updated the version of zombie to ^6 in package.json so that gulp-test works for NodeJS 6 or higher.
We added a new nsXDCookie with a new function asyncGet which is async version of the original 'get' function.
Installing
Usng npm:
npm install @nuskin/ns-xdcookies
Usng yarn:
yarn add @nuskin/ns-xdcookies
Example usage
const { nsXDCookie } = require('@nuskin/ns-xdcookies')
// Note that this library will be used ONLY in the browser (client side)
// It is recommended that developers call nsXDCookie() sparingly because
// it creates a new hidden iframe with the network call.
// Normally, you can just initiate nsXDCookie() once. However, if the user needs to switch
// between two domains multiple times, then you may want to do it as needed.
// Set all the default settings with a default
// iframeURL (https://nse-www-nuskin-com-static.s3.amazonaws.com/hidden/xdomain)
const nsXDC = nsXDCookie();
// Set the cross domain cookie named 'myCookieName' with the value 'myCookieValue'.
nsXDC.set('myCookieName', 'myCookieValue');
// Get the cross domain cookie named 'myCookieName'.
// Note that it will retrieve the cookies from the iframe and it is asynchronized call.
let cookieValue = await nsXDC.asyncGet('myCookieName');
// Or you can get the cookies with a callback:
nsXDC.get('myCookieName', (val) => {
let cookieValue = val;
});
Resources
- Changelog could go here