Skip to content

Commit 0450b57

Browse files
nysos3pi0
authored andcommitted
fix(storage): use false value for unsetting token/user (#160)
#133
1 parent 42b4061 commit 0450b57

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/core/auth.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ export default class Auth {
150150

151151
reset () {
152152
if (!this.strategy.reset) {
153-
this.setUser(null)
154-
this.setToken(this.$state.strategy, null)
155-
this.setRefreshToken(this.$state.strategy, null)
153+
this.setUser(false)
154+
this.setToken(this.$state.strategy, false)
155+
this.setRefreshToken(this.$state.strategy, false)
156156
return Promise.resolve()
157157
}
158158

@@ -270,8 +270,7 @@ export default class Auth {
270270
if (!_endpoint.headers) {
271271
_endpoint.headers = {}
272272
}
273-
274-
if (!_endpoint.headers['Authorization'] && isSet(token)) {
273+
if (!_endpoint.headers['Authorization'] && isSet(token) && token) {
275274
_endpoint.headers['Authorization'] = token
276275
}
277276

lib/core/storage.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ export default class Storage {
156156
const _key = this.options.localStorage.prefix + key
157157

158158
const value = localStorage.getItem(_key)
159+
if (value === 'false') {
160+
return false
161+
}
159162

160163
return isJson ? JSON.parse(value) : value
161164
}
@@ -195,7 +198,9 @@ export default class Storage {
195198

196199
const cookies = parseCookie(cookieStr || '') || {}
197200
const value = cookies[_key]
198-
201+
if (value === 'false') {
202+
return false
203+
}
199204
return isJson ? JSON.parse(value) : value
200205
}
201206
}

0 commit comments

Comments
 (0)