Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Commit 5cfee8a

Browse files
committed
refactor(auth.ts): refactor getTokenFromCookie
1 parent 7a70233 commit 5cfee8a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/utilities/auth.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ export const unsetToken = (): void => {
1111

1212
// @ts-ignore
1313
export const getTokenFromCookie = (req: any): string | undefined => {
14+
// SSR
1415
if (req && req.headers.cookie) {
16+
console.log('req.headers.cookie:', req.headers.cookie)
1517
const cookie: string = req.headers.cookie
1618
.split(';')
1719
.find((c: string) => c.trim().startsWith('token='))
18-
.split('=')[1]
19-
return cookie
20+
21+
if (!cookie) {
22+
return ''
23+
}
24+
25+
const token = cookie.split('=')[1]
26+
return token
2027
}
2128

29+
// CSR
2230
return Cookie.get('token')
2331
}

0 commit comments

Comments
 (0)