From dbfa18bb950ceeb608a3da87aa232341929b594e Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 8 Jan 2024 16:07:31 -0300 Subject: [PATCH] Fix login delay and add access token to every request --- src/frontend/src/contexts/authContext.tsx | 4 +--- src/frontend/src/controllers/API/api.tsx | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/contexts/authContext.tsx b/src/frontend/src/contexts/authContext.tsx index b220c1e49..9ebb34756 100644 --- a/src/frontend/src/contexts/authContext.tsx +++ b/src/frontend/src/contexts/authContext.tsx @@ -98,9 +98,7 @@ export function AuthProvider({ children }): React.ReactElement { function login(newAccessToken: string) { setAccessToken(newAccessToken); setIsAuthenticated(true); - setTimeout(() => { - getUser(); - }, 500); + getUser(); } async function logout() { diff --git a/src/frontend/src/controllers/API/api.tsx b/src/frontend/src/controllers/API/api.tsx index 27d98f43c..4e9151f15 100644 --- a/src/frontend/src/controllers/API/api.tsx +++ b/src/frontend/src/controllers/API/api.tsx @@ -104,6 +104,7 @@ function ApiInterceptor() { // Request interceptor to add access token to every request const requestInterceptor = api.interceptors.request.use( (config) => { + const accessToken = cookies.get("access_token_lf"); if (accessToken && !isAuthorizedURL(config?.url)) { config.headers["Authorization"] = `Bearer ${accessToken}`; }