Skip to content

Commit

Permalink
fix(storage): use false value for unsetting token/user (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
nysos3 authored and pi0 committed Apr 29, 2018
1 parent 42b4061 commit 0450b57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/core/auth.js
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 6 additions & 1 deletion lib/core/storage.js
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
}

0 comments on commit 0450b57

Please sign in to comment.