From 0450b57d6064b37d38f332cd99bcc13d2d0e713b Mon Sep 17 00:00:00 2001 From: Cody Carrell Date: Sun, 29 Apr 2018 16:02:35 -0400 Subject: [PATCH] fix(storage): use false value for unsetting token/user (#160) nuxt-community/auth-module#133 --- lib/core/auth.js | 9 ++++----- lib/core/storage.js | 7 ++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/core/auth.js b/lib/core/auth.js index 679144c6d..4cf74672d 100644 --- a/lib/core/auth.js +++ b/lib/core/auth.js @@ -150,9 +150,9 @@ export default class Auth { reset () { if (!this.strategy.reset) { - this.setUser(null) - this.setToken(this.$state.strategy, null) - this.setRefreshToken(this.$state.strategy, null) + this.setUser(false) + this.setToken(this.$state.strategy, false) + this.setRefreshToken(this.$state.strategy, false) return Promise.resolve() } @@ -270,8 +270,7 @@ export default class Auth { if (!_endpoint.headers) { _endpoint.headers = {} } - - if (!_endpoint.headers['Authorization'] && isSet(token)) { + if (!_endpoint.headers['Authorization'] && isSet(token) && token) { _endpoint.headers['Authorization'] = token } diff --git a/lib/core/storage.js b/lib/core/storage.js index bfbe42a81..d3658a725 100644 --- a/lib/core/storage.js +++ b/lib/core/storage.js @@ -156,6 +156,9 @@ export default class Storage { const _key = this.options.localStorage.prefix + key const value = localStorage.getItem(_key) + if (value === 'false') { + return false + } return isJson ? JSON.parse(value) : value } @@ -195,7 +198,9 @@ export default class Storage { const cookies = parseCookie(cookieStr || '') || {} const value = cookies[_key] - + if (value === 'false') { + return false + } return isJson ? JSON.parse(value) : value } }