forked from skillrecordings/egghead-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaffiliateToken.ts
More file actions
36 lines (30 loc) · 874 Bytes
/
Copy pathaffiliateToken.ts
File metadata and controls
36 lines (30 loc) · 874 Bytes
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
28
29
30
31
32
33
34
35
36
import {
AFFILIATE_TOKEN_KEY,
SIGNED_AFFILIATE_TOKEN_KEY,
} from '../hooks/use-token-signer'
import cookies from './cookies'
export type AffiliateToken = {
token: string | null
signed: boolean
}
const nullAffiliateToken: AffiliateToken = {
token: null,
signed: false,
}
export const getAffiliateTokenFromCookie = (): AffiliateToken => {
const signedToken = cookies.get(SIGNED_AFFILIATE_TOKEN_KEY)
const token = cookies.get(AFFILIATE_TOKEN_KEY)
if (!signedToken && !token) return nullAffiliateToken
return {
token: signedToken || token,
signed: !!signedToken,
}
}
export const removeAffiliateTokenFromCookie = async () => {
const cookieOptions = {
path: '',
domain: process.env.NEXT_PUBLIC_AUTH_COOKIE_DOMAIN,
}
cookies.remove(SIGNED_AFFILIATE_TOKEN_KEY, cookieOptions)
cookies.remove(AFFILIATE_TOKEN_KEY, cookieOptions)
}