diff --git a/backend/python/app/rest/auth_routes.py b/backend/python/app/rest/auth_routes.py index 77061d5..54c5c7a 100644 --- a/backend/python/app/rest/auth_routes.py +++ b/backend/python/app/rest/auth_routes.py @@ -31,6 +31,7 @@ "httponly": True, "samesite": ("None" if os.getenv("PREVIEW_DEPLOY") else "Strict"), "secure": (os.getenv("FLASK_CONFIG") == "production"), + "max_age": 60 * 60 * 24 , # 1 day } diff --git a/frontend/src/APIClients/AuthAPIClient.ts b/frontend/src/APIClients/AuthAPIClient.ts index 4f784e5..5069cf2 100644 --- a/frontend/src/APIClients/AuthAPIClient.ts +++ b/frontend/src/APIClients/AuthAPIClient.ts @@ -134,7 +134,7 @@ type LogoutFunction = ( FetchResult< { logout: null; - }, + }, Record, Record > diff --git a/frontend/src/APIClients/BaseAPIClient.ts b/frontend/src/APIClients/BaseAPIClient.ts index f14fe95..7f026e1 100644 --- a/frontend/src/APIClients/BaseAPIClient.ts +++ b/frontend/src/APIClients/BaseAPIClient.ts @@ -42,6 +42,7 @@ baseAPIClient.interceptors.request.use(async (config: AxiosRequestConfig) => { (typeof decodedToken === "string" || decodedToken.exp <= Math.round(new Date().getTime() / 1000)) ) { + try { const { data } = await axios.post( `${process.env.REACT_APP_BACKEND_URL}/auth/refresh`, {}, @@ -56,6 +57,10 @@ baseAPIClient.interceptors.request.use(async (config: AxiosRequestConfig) => { ); newConfig.headers.Authorization = `Bearer ${accessToken}`; + } catch (error) { + localStorage.removeItem(AUTHENTICATED_USER_KEY); + window.location.href = "/login"; + } } } diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index a11d6a2..a0aa7f6 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -49,6 +49,7 @@ const authLink = setContext(async (_, { headers }) => { (typeof decodedToken === "string" || decodedToken.exp <= Math.round(new Date().getTime() / 1000)) ) { + try { const { data } = await axios.post( `${process.env.REACT_APP_BACKEND_URL}/graphql`, { query: REFRESH_MUTATION }, @@ -62,6 +63,10 @@ const authLink = setContext(async (_, { headers }) => { accessToken, ); token = accessToken; + } catch { + localStorage.removeItem(AUTHENTICATED_USER_KEY); + window.location.reload(); + } } } // return the headers to the context so httpLink can read them