Skip to content

Commit 037d58b

Browse files
Merge pull request #585 from GaborTorma/client-init-auth
fix: support client side initAuth
2 parents 0d76efd + 93a1cf6 commit 037d58b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/utils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,18 @@ export const initAuth = function initAuth(options) {
163163
'You must pass the `commit` function in the `initAuth` function options.'
164164
)
165165
}
166-
if (!req) {
166+
let cookies
167+
if (req) {
168+
cookies = req.headers.cookie
169+
} else if (document && document.cookie) {
170+
cookies = document.cookie
171+
} else {
167172
throw new Error(
168173
'You must pass the `req` object in the `initAuth` function options.'
169174
)
170175
}
171176

172-
const accessToken = readCookie(req.headers.cookie, cookieName)
177+
const accessToken = readCookie(cookies, cookieName)
173178
const payload = getValidPayloadFromToken(accessToken)
174179

175180
if (payload) {

0 commit comments

Comments
 (0)