-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cookie of inviter id perist (#15)
- Loading branch information
AceDataCloud
committed
Jan 2, 2024
1 parent
37a66dc
commit be42c39
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@zhishuyun-hub-656f97b1-d2bb-424f-8aff-9d5fcdc142eb.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "add inviter id cookies persist", | ||
"packageName": "@zhishuyun/hub", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './baseUrl'; | ||
export * from './mode'; | ||
export * from './log'; | ||
export * from './cookies'; |