Skip to content

Commit f4d0554

Browse files
Intevelbmulholland
andauthored
fix: Setting cookie: false is not respected (#1442)
* fix: Setting cookie: false is not respected * fix: Setting cookie: false is not respected Co-Authored-By: Brendan Mulholland <[email protected]> * Update storage.ts Co-authored-by: Brendan Mulholland <[email protected]>
1 parent d498480 commit f4d0554

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/core/storage.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ export class Storage {
232232
// Cookies
233233
// ------------------------------------
234234
getCookies(): Record<string, unknown> {
235+
if (!this.isCookiesEnabled()) {
236+
return
237+
}
235238
const cookieStr = process.client
236239
? document.cookie
237240
: this.ctx.req.headers.cookie
@@ -248,6 +251,10 @@ export class Storage {
248251
return
249252
}
250253

254+
if (!this.isCookiesEnabled()) {
255+
return
256+
}
257+
251258
const _prefix =
252259
options.prefix !== undefined ? options.prefix : this.options.cookie.prefix
253260
const _key = _prefix + key
@@ -293,6 +300,10 @@ export class Storage {
293300
return
294301
}
295302

303+
if (!this.isCookiesEnabled()) {
304+
return
305+
}
306+
296307
const _key = this.options.cookie.prefix + key
297308

298309
const cookies = this.getCookies()
@@ -345,4 +356,28 @@ export class Storage {
345356
return false
346357
}
347358
}
359+
360+
isCookiesEnabled(): boolean {
361+
// Disabled by configuration
362+
if (!this.options.cookie) {
363+
return false
364+
}
365+
366+
// Server can only assume cookies are enabled, it's up to the client browser
367+
// to create them or not
368+
if (process.server) {
369+
return true
370+
}
371+
372+
if (window.navigator.cookieEnabled) {
373+
return true
374+
} else {
375+
// eslint-disable-next-line no-console
376+
console.warn(
377+
"[AUTH] Cookies is enabled in config, but browser doesn't" +
378+
' support it'
379+
)
380+
return false
381+
}
382+
}
348383
}

0 commit comments

Comments
 (0)