ФУНКЦИИ - NODEDC LAUNCHER: preserve auth returnTo

This commit is contained in:
DCCONSTRUCTIONS
2026-05-04 22:07:14 +03:00
parent a1e8cacd88
commit 8e6d2cea39
+15 -1
View File
@@ -187,7 +187,7 @@ export function LauncherApp() {
useEffect(() => { useEffect(() => {
if (!authSession || authSession.authenticated) return; if (!authSession || authSession.authenticated) return;
window.location.replace(authSession.loginUrl || "/auth/login"); window.location.replace(buildLoginRedirectUrl(authSession.loginUrl));
}, [authSession]); }, [authSession]);
useEffect(() => { useEffect(() => {
@@ -658,3 +658,17 @@ function AuthStateScreen({
</div> </div>
); );
} }
function buildLoginRedirectUrl(loginUrl?: string) {
const url = new URL(loginUrl || "/auth/login", window.location.origin);
if (!url.searchParams.has("returnTo")) {
const returnTo = `${window.location.pathname}${window.location.search}${window.location.hash}`;
if (returnTo && returnTo !== "/") {
url.searchParams.set("returnTo", returnTo);
}
}
return url.origin === window.location.origin ? `${url.pathname}${url.search}${url.hash}` : url.toString();
}