Files
2026-10-03 14:51:40 +07:00

13 lines
524 B
TypeScript

export function safeAuthReturnPath(value: unknown): string {
if (typeof value !== "string" || !value.startsWith("/")) return "/";
try {
const url = new URL(value, "https://auth.local");
const path = decodeURIComponent(url.pathname);
if (url.origin !== "https://auth.local" || path === "/auth" || path.startsWith("/auth/") || ["/login", "/register", "/commission/login", "/admin/login"].includes(path))
return "/";
return `${url.pathname}${url.search}${url.hash}`;
} catch {
return "/";
}
}