Files
personal-website/src/lib/auth-redirect.ts
Stan Runge d0c7b6548b
Some checks failed
Test and deploy staging / staging (push) Has been cancelled
beeeeg update
2026-09-23 04:16:50 +00:00

14 lines
423 B
TypeScript

export function safeReturnTo(value: string | null): string {
if (!value || !value.startsWith('/') || value.startsWith('//') || /[\\\s]/.test(value)) {
return '/account';
}
const url = new URL(value, 'https://local.invalid');
if (
url.origin !== 'https://local.invalid' ||
/^\/(api\/auth|login|register|logout)(\/|$)/.test(url.pathname)
) {
return '/account';
}
return url.pathname + url.search + url.hash;
}