@clerk/shared
Version:
Internal package utils used by the Clerk SDKs
41 lines (39 loc) • 1.1 kB
JavaScript
import Cookies from "js-cookie";
//#region src/cookie.ts
/**
* Creates helper methods for dealing with a specific cookie.
*
* @example
* ```ts
* const cookie = createCookieHandler('my_cookie')
*
* cookie.set('my_value');
* cookie.get() // 'my_value';
* cookie.remove()
* ```
*/
function createCookieHandler(cookieName) {
return {
get() {
return Cookies.get(cookieName);
},
/**
* Setting a cookie will use some defaults such as path being set to "/".
*/
set(newValue, options = {}) {
Cookies.set(cookieName, newValue, options);
},
/**
* On removing a cookie, you have to pass the exact same path/domain attributes used to set it initially
* > IMPORTANT! When deleting a cookie and you're not relying on the default attributes, you must pass the exact same path, domain, secure and sameSite attributes that were used to set the cookie.
*
* @see https://github.com/js-cookie/js-cookie#basic-usage
*/
remove(cookieAttributes) {
Cookies.remove(cookieName, cookieAttributes);
}
};
}
//#endregion
export { createCookieHandler };
//# sourceMappingURL=cookie.mjs.map