From 91976e23f989f39fb25d3341aa3f4b632ea66f35 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 15 Sep 2022 12:35:53 +0200 Subject: [PATCH] fix: redirect to login when the jwt token expires --- src/store/modules/auth.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/store/modules/auth.ts b/src/store/modules/auth.ts index 2e6249109..7457a0aa5 100644 --- a/src/store/modules/auth.ts +++ b/src/store/modules/auth.ts @@ -13,7 +13,7 @@ import {redirectToProvider} from '@/helpers/redirectToProvider' import type { RootStoreState, AuthState, Info} from '@/store/types' import {AUTH_TYPES} from '@/store/types' import type { IUserSettings } from '@/modelTypes/IUserSettings' - +import router from '@/router' function defaultSettings(settings: Partial) { if (typeof settings.weekStart === 'undefined' || settings.weekStart === '') { @@ -240,6 +240,10 @@ const authStore : Module = { return info } catch (e) { + if(e?.response?.data?.message === 'invalid or expired jwt') { + dispatch('logout') + return + } throw new Error('Error while refreshing user info:', {cause: e}) } }, @@ -289,6 +293,7 @@ const authStore : Module = { logout(ctx) { removeToken() window.localStorage.clear() // Clear all settings and history we might have saved in local storage. + router.push({name: 'user.login'}) ctx.dispatch('checkAuth') }, },