mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-13 01:32:40 +02:00
fix(auth): centralize redirect path storage
This commit is contained in:
parent
c8374e6c5b
commit
fb0c13911d
3 changed files with 14 additions and 5 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue