From e9f55d065afd28794250e28067870aeba576d671 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 15 Sep 2022 15:07:10 +0200 Subject: [PATCH] Client - disconnect user when stored token is blacklisted --- fittrackee_client/src/utils/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fittrackee_client/src/utils/index.ts b/fittrackee_client/src/utils/index.ts index bbdd3f6f..0cc2c51f 100644 --- a/fittrackee_client/src/utils/index.ts +++ b/fittrackee_client/src/utils/index.ts @@ -1,7 +1,7 @@ import { AxiosError } from 'axios' import { ActionContext } from 'vuex' -import { ROOT_STORE } from '@/store/constants' +import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants' import { IAuthUserState } from '@/store/modules/authUser/types' import { IOAuth2State } from '@/store/modules/oauth2/types' import { IRootState } from '@/store/modules/root/types' @@ -28,6 +28,15 @@ export const handleError = ( error: AxiosError | null, msg = 'UNKNOWN' ): void => { + // if stored token is blacklisted + if ( + error?.response?.status === 401 && + error.response.data.error === 'invalid_token' + ) { + localStorage.removeItem('authToken') + context.dispatch(AUTH_USER_STORE.ACTIONS.CHECK_AUTH_USER) + return + } const errorMessages = !error ? msg : error.response