forked from clerk/javascript
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie.ts
27 lines (25 loc) · 763 Bytes
/
cookie.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Cookies from 'js-cookie';
type LocationAttributes = {
path?: string;
domain?: string;
};
export function createCookieHandler(cookieName: string) {
return {
get() {
return Cookies.get(cookieName);
},
/**
* Setting a cookie will use some defaults such as path being set to "/".
*/
set(newValue: string, options: Cookies.CookieAttributes = {}): void {
Cookies.set(cookieName, newValue, options);
},
/**
* On removing a cookie, you have to pass the exact same path/domain attributes used to set it initially
* @see https://github.com/js-cookie/js-cookie#basic-usage
*/
remove(locationAttributes?: LocationAttributes) {
Cookies.remove(cookieName, locationAttributes);
},
};
}