From 723e6dd13f9b8fd20182f03daff3249ccf98fe22 Mon Sep 17 00:00:00 2001 From: Jai A Date: Mon, 29 Mar 2021 18:34:57 -0700 Subject: [PATCH] Fix auth again --- layouts/default.vue | 7 +++---- middleware/auth.js | 7 +++++-- pages/dashboard/misc/revoke-token.vue | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/layouts/default.vue b/layouts/default.vue index 74cea213..1024a5bc 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -162,10 +162,9 @@ export default { hideDropdown() { this.isDropdownOpen = false }, - logout() { - this.$auth.user = null - this.$cookies.remove('auth-token') - this.$router.go(null) + async logout() { + this.$cookies.set('auth-token-reset', true) + await this.$router.go(null) }, changeTheme() { this.$colorMode.preference = diff --git a/middleware/auth.js b/middleware/auth.js index 622d1371..68d31e7d 100644 --- a/middleware/auth.js +++ b/middleware/auth.js @@ -10,12 +10,15 @@ export default async function (context) { return context.redirect(context.route.path) } + if (context.app.$cookies.get('auth-token-reset')) { + context.app.$cookies.removeAll() + return + } + if (context.app.$cookies.get('auth-token')) { const cookie = context.app.$cookies.get('auth-token') await context.store.dispatch('auth/fetchUser', { token: cookie }) - } else { - context.$auth.user = null } } diff --git a/pages/dashboard/misc/revoke-token.vue b/pages/dashboard/misc/revoke-token.vue index 99434716..1723a333 100644 --- a/pages/dashboard/misc/revoke-token.vue +++ b/pages/dashboard/misc/revoke-token.vue @@ -54,8 +54,7 @@ export default { }, methods: { async logout() { - this.$auth.user = null - this.$cookies.remove('auth-token') + this.$cookies.set('auth-token-reset', true) await this.$router.replace( 'https://api.modrinth.com/api/v1/auth/init?url=https://modrinth.com/' )