Skip to content

Commit

Permalink
fix(refresh scheme): fix reset
Browse files Browse the repository at this point in the history
Based on #544
  • Loading branch information
JoaoPedroAS51 committed Mar 3, 2020
1 parent b2937ab commit 02daa79
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/schemes/refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class RefreshScheme extends LocalScheme {
).then(response => {
this._updateTokens(response)
}).catch(error => {
this._logoutLocally()
this.$auth.reset()
this.$auth.callOnError(error, { method: 'refreshToken' })
})
}
Expand Down Expand Up @@ -200,9 +200,9 @@ export default class RefreshScheme extends LocalScheme {
// Update Authorization header
config.headers[this.options.tokenName] = this.$auth.getToken(this.name)
return Promise.resolve(config)
}).catch(() => this._logoutLocally())
})
} else {
this._logoutLocally()
this.$auth.reset()
}
}
} else if (config.url !== this.options.endpoints.refresh.url) {
Expand Down Expand Up @@ -230,9 +230,9 @@ export default class RefreshScheme extends LocalScheme {
const refreshTokenExpiration = this._syncRefreshTokenExpiration()

if (refreshTokenExpiration && now >= new Date(refreshTokenExpiration).setMilliseconds(0)) {
await this._logoutLocally()
await this.$auth.reset()
} else if (this.options.autoLogout && tokenExpiration && now >= new Date(tokenExpiration).setMilliseconds(0)) {
await this._logoutLocally()
await this.$auth.reset()
}

this._syncClientId()
Expand Down Expand Up @@ -262,7 +262,7 @@ export default class RefreshScheme extends LocalScheme {
if (!this.options.endpoints.login) return

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

// Make login request
const loginResult = await this.$auth.request(endpoint, this.options.endpoints.login)
Expand Down Expand Up @@ -320,7 +320,7 @@ export default class RefreshScheme extends LocalScheme {
return super.logout(endpoint)
}

async _logoutLocally () {
async reset () {
this._clearToken()
clearInterval(this.refreshInterval)

Expand All @@ -331,8 +331,10 @@ export default class RefreshScheme extends LocalScheme {
this._setTokenExpiration(false)
this._setRefreshTokenExpiration(false)
this._setClientId(false)
this.$auth.setUser(false)
this.$auth.setToken(this.name, false)

return this.$auth.reset()
return Promise.resolve()
}
}

Expand Down

0 comments on commit 02daa79

Please sign in to comment.