Add Cookie of inviter id perist (#15)

This commit is contained in:
AceDataCloud committed 2024-01-02 14:55:36 +08:00
1 parent 37a66dc419
commit be42c390be
4 files changed
+57 -1

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import { removeCookie, setCookie as baseSetCookie } from 'typescript-cookie';
import { CookieAttributes } from 'typescript-cookie/dist/types';
export const getDomain = () => {
const host = window.location.host;
// process test env and prod env, for example:
// auth.zhishuyun.com -> .zhishuyun.com
// auth.test.zhishuyun.com -> .zhishuyun.com
const domain = host.replace(/^\S+?\.(test\.|local\.)?/, '.');
return domain;
};
export const getPath = () => {
return '/';
};
export const setCookie = (key: string, value: string, attributes: CookieAttributes) => {
baseSetCookie(key, value, {
domain: attributes?.domain || getDomain(),
path: attributes?.path || getPath(),
expires: attributes?.expires,
sameSite: attributes?.sameSite,
secure: attributes?.secure
});
};
export const resetCookies = () => {
// remove tokens from cookies
removeCookie('ACCESS_TOKEN', { domain: getDomain(), path: getPath() });
removeCookie('REFRESH_TOKEN', { domain: getDomain(), path: getPath() });
};
+1
View File
@@ -1,3 +1,4 @@
export * from './baseUrl';
export * from './mode';
export * from './log';
export * from './cookies';