From e39fc3d2118370740e5960380d559012a0657872 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 14 Sep 2022 16:33:53 +0200 Subject: [PATCH] Client - call api endpoint on logout to blacklist token --- .../src/store/modules/authUser/actions.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/fittrackee_client/src/store/modules/authUser/actions.ts b/fittrackee_client/src/store/modules/authUser/actions.ts index 26e3716b..25a41e00 100644 --- a/fittrackee_client/src/store/modules/authUser/actions.ts +++ b/fittrackee_client/src/store/modules/authUser/actions.ts @@ -59,6 +59,13 @@ export const actions: ActionTree & ) context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE) } + // after logout in another tab + if ( + !window.localStorage.authToken && + context.getters[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED] + ) { + removeAuthUserData(context) + } }, [AUTH_USER_STORE.ACTIONS.CONFIRM_ACCOUNT]( context: ActionContext, @@ -182,7 +189,17 @@ export const actions: ActionTree & [AUTH_USER_STORE.ACTIONS.LOGOUT]( context: ActionContext ): void { - removeAuthUserData(context) + context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES) + authApi + .post('auth/logout') + .then((res) => { + if (res.data.status === 'success') { + removeAuthUserData(context) + } else { + handleError(context, null) + } + }) + .catch((error) => handleError(context, error)) }, [AUTH_USER_STORE.ACTIONS.UPDATE_USER_PROFILE]( context: ActionContext,