From e7f46229c98026ba7776da948cc0ce51219c0fd8 Mon Sep 17 00:00:00 2001 From: Fernando Nogueira Date: Sat, 30 May 2026 22:49:13 +0100 Subject: [PATCH] fix: remember current path for post-login redirect in case token expired --- src/context/auth/axios.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/context/auth/axios.ts b/src/context/auth/axios.ts index 389a971..81fe369 100644 --- a/src/context/auth/axios.ts +++ b/src/context/auth/axios.ts @@ -2,6 +2,13 @@ import axios from 'axios'; import {API_URL} from "../../configs.ts"; import {useAuthState} from "./hook.ts"; +const rememberCurrentPathForPostLoginRedirect = () => { + const currentPath = window.location.pathname + window.location.search + window.location.hash; + if (currentPath && !currentPath.startsWith('/login')) { + sessionStorage.setItem('redirectAfterLogin', currentPath); + } +}; + const useAxios = () => { const {token} = useAuthState(); @@ -24,6 +31,7 @@ const useAxios = () => { (error) => { if (error.response?.status === 401) { localStorage.removeItem('authState'); + rememberCurrentPathForPostLoginRedirect(); window.location.assign('/login'); } return Promise.reject(error);