From ab75ebcd54d45c79d060b810cfd2ba90fd5738ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Antunes=20Silva?= Date: Tue, 3 Mar 2020 10:53:48 -0300 Subject: [PATCH] fix: clear tokens when calling `$auth.reset()` (#544) fixes #172 --- lib/schemes/local.js | 14 +++++++++----- lib/schemes/oauth2.js | 9 +++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/schemes/local.js b/lib/schemes/local.js index e5d46c705..4b2f95c70 100644 --- a/lib/schemes/local.js +++ b/lib/schemes/local.js @@ -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, @@ -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() } } diff --git a/lib/schemes/oauth2.js b/lib/schemes/oauth2.js index 9d8cc2d80..a8299eefe 100644 --- a/lib/schemes/oauth2.js +++ b/lib/schemes/oauth2.js @@ -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 } = {}) {