@@ -232,6 +232,9 @@ export class Storage {
232
232
// Cookies
233
233
// ------------------------------------
234
234
getCookies ( ) : Record < string , unknown > {
235
+ if ( ! this . isCookiesEnabled ( ) ) {
236
+ return
237
+ }
235
238
const cookieStr = process . client
236
239
? document . cookie
237
240
: this . ctx . req . headers . cookie
@@ -248,6 +251,10 @@ export class Storage {
248
251
return
249
252
}
250
253
254
+ if ( ! this . isCookiesEnabled ( ) ) {
255
+ return
256
+ }
257
+
251
258
const _prefix =
252
259
options . prefix !== undefined ? options . prefix : this . options . cookie . prefix
253
260
const _key = _prefix + key
@@ -293,6 +300,10 @@ export class Storage {
293
300
return
294
301
}
295
302
303
+ if ( ! this . isCookiesEnabled ( ) ) {
304
+ return
305
+ }
306
+
296
307
const _key = this . options . cookie . prefix + key
297
308
298
309
const cookies = this . getCookies ( )
@@ -345,4 +356,28 @@ export class Storage {
345
356
return false
346
357
}
347
358
}
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
+ }
348
383
}
0 commit comments