Skip to content

Commit

Permalink
fix: Setting cookie: false is not respected (#1442)
Browse files Browse the repository at this point in the history
* fix: Setting cookie: false is not respected

* fix: Setting cookie: false is not respected

Co-Authored-By: Brendan Mulholland <github@bmulholland.ca>

* Update storage.ts

Co-authored-by: Brendan Mulholland <github@bmulholland.ca>
  • Loading branch information
Intevel and bmulholland committed Jan 19, 2022
1 parent d498480 commit f4d0554
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/core/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ export class Storage {
// Cookies
// ------------------------------------
getCookies(): Record<string, unknown> {
if (!this.isCookiesEnabled()) {
return
}
const cookieStr = process.client
? document.cookie
: this.ctx.req.headers.cookie
Expand All @@ -248,6 +251,10 @@ export class Storage {
return
}

if (!this.isCookiesEnabled()) {
return
}

const _prefix =
options.prefix !== undefined ? options.prefix : this.options.cookie.prefix
const _key = _prefix + key
Expand Down Expand Up @@ -293,6 +300,10 @@ export class Storage {
return
}

if (!this.isCookiesEnabled()) {
return
}

const _key = this.options.cookie.prefix + key

const cookies = this.getCookies()
Expand Down Expand Up @@ -345,4 +356,28 @@ export class Storage {
return false
}
}

isCookiesEnabled(): boolean {
// Disabled by configuration
if (!this.options.cookie) {
return false
}

// Server can only assume cookies are enabled, it's up to the client browser
// to create them or not
if (process.server) {
return true
}

if (window.navigator.cookieEnabled) {
return true
} else {
// eslint-disable-next-line no-console
console.warn(
"[AUTH] Cookies is enabled in config, but browser doesn't" +
' support it'
)
return false
}
}
}

0 comments on commit f4d0554

Please sign in to comment.