From 329b8f83e7a94feaadc06affa32d381c3406c67a Mon Sep 17 00:00:00 2001 From: Juliano Date: Thu, 7 Dec 2023 21:32:52 -0300 Subject: [PATCH] Fixes invalid 2fa token signing out user --- frontend/src/services/api.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index debe5c81..d56069d0 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -1,4 +1,4 @@ -import { TokenPayload, signOut } from "@/contexts/AuthContext"; +import { signOut } from "@/contexts/AuthContext"; import axios, { AxiosError } from "axios"; import nookies from "nookies"; import { GetServerSidePropsContext } from "next"; @@ -25,12 +25,21 @@ export function setupAPIClient(ctx: Context = undefined) { } ); + type ResponseData = { + error: string; + message: string; + statusCode: number; + }; + api.interceptors.response.use( (response) => { return response; }, - (error: AxiosError) => { - if (error.response?.status === 401) { + (error: AxiosError) => { + if ( + error.response?.status === 401 && + error.response?.data?.message !== "Invalid 2FA code" + ) { // TODO refresh if access token is invalid // TODO if refresh token is invalid, logout and delete cookies if (process.browser) {