This commit is contained in:
13
src/lib/auth-redirect.ts
Normal file
13
src/lib/auth-redirect.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user