Skip to content

Commit

Permalink
fix: clear tokens when calling $auth.reset() (#544)
Browse files Browse the repository at this point in the history
fixes #172
  • Loading branch information
JoaoPedroAS51 authored Mar 3, 2020
1 parent d3a0b3e commit ab75ebc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 9 additions & 5 deletions lib/schemes/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class LocalScheme {
}

// Ditch any leftover local tokens before attempting to log in
await this._logoutLocally()
await this.$auth.reset()

const result = await this.$auth.request(
endpoint,
Expand Down Expand Up @@ -93,16 +93,20 @@ export default class LocalScheme {
.catch(() => { })
}

// But logout locally regardless
return this._logoutLocally()
// But reset regardless
return this.$auth.reset()
}

async _logoutLocally () {
async reset () {
if (this.options.tokenRequired) {
this._clearToken()
}

return this.$auth.reset()
this.$auth.setUser(false)
this.$auth.setToken(this.name, false)
this.$auth.setRefreshToken(this.name, false)

return Promise.resolve()
}
}

Expand Down
9 changes: 7 additions & 2 deletions lib/schemes/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ export default class Oauth2Scheme {
this.$auth.ctx.app.$axios.setHeader(this.options.tokenName, false)
}

async logout () {
async reset () {
this._clearToken()
return this.$auth.reset()

this.$auth.setUser(false)
this.$auth.setToken(this.name, false)
this.$auth.setRefreshToken(this.name, false)

return Promise.resolve()
}

login ({ params, state, nonce } = {}) {
Expand Down

0 comments on commit ab75ebc

Please sign in to comment.