DocDoeAI / src /lib /auth /next-path.ts
asnannp's picture
deploy: sync backend to Space root (learn-lesson HF cache fix)
65d68f5
Raw History Blame Contribute Delete
678 Bytes
/** Safe post-auth redirect path from `?next=` (SSR + client). */
const BLOCKED_NEXT_PREFIXES = ["/login", "/signup", "/logout", "/forgot-password", "/reset-password"] as const;
function isBlockedNextPath(path: string): boolean {
return BLOCKED_NEXT_PREFIXES.some(
(prefix) => path === prefix || path.startsWith(`${prefix}?`) || path.startsWith(`${prefix}/`),
);
}
export function resolveNextPath(
requested: string | null | undefined,
fallback = "/study-chat",
): string {
if (!requested || !requested.startsWith("/") || requested.startsWith("//")) {
return fallback;
}
if (isBlockedNextPath(requested)) {
return fallback;
}
return requested;
}