fix(auth): centralize redirect path storage

This commit is contained in:
너이름 2026-05-11 06:30:26 +09:00
parent c8374e6c5b
commit fb0c13911d
3 changed files with 14 additions and 5 deletions

View file

@ -60,12 +60,20 @@ export function handleUnauthorized(): void {
const currentPath = pathname + window.location.search + window.location.hash;
const excludedPaths = ["/auth", "/auth/callback", "/"];
if (!excludedPaths.includes(pathname)) {
localStorage.setItem(REDIRECT_PATH_KEY, currentPath);
setRedirectPath(currentPath);
}
window.location.href = getLoginPath();
}
}
/**
* Stores the path to redirect to after successful authentication.
*/
export function setRedirectPath(path: string): void {
if (typeof window === "undefined") return;
localStorage.setItem(REDIRECT_PATH_KEY, path);
}
/**
* Gets the stored redirect path and clears it from storage
* Call this after successful login to redirect the user back
@ -230,7 +238,7 @@ export function redirectToLogin(): void {
// Don't save auth-related paths or home page
const excludedPaths = ["/auth", "/auth/callback", "/", "/login", "/register", "/desktop/login"];
if (!excludedPaths.includes(window.location.pathname)) {
localStorage.setItem(REDIRECT_PATH_KEY, currentPath);
setRedirectPath(currentPath);
}
window.location.href = getLoginPath();