Skip to content

Commit

Permalink
Fixes invalid 2fa token signing out user (#166)
Browse files Browse the repository at this point in the history
Co-authored-by: Juliano <[email protected]>
  • Loading branch information
julianochoi and Juliano authored Dec 8, 2023
1 parent 9ecbdf6 commit 4be36d8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions frontend/src/services/api.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<ResponseData>) => {
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) {
Expand Down

0 comments on commit 4be36d8

Please sign in to comment.