20 lines
542 B
TypeScript
20 lines
542 B
TypeScript
import type { LocationQuery } from 'vue-router';
|
|||
|
|
|
||
|
|
export function sanitizeRedirectPath(value: unknown): string | null {
|
||
|
|
if (typeof value !== 'string' || !value.startsWith('/') || value.startsWith('//')) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
return value;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function redirectFromQuery(query: LocationQuery, fallback = '/app'): string {
|
||
|
|
return sanitizeRedirectPath(query.redirect) ?? fallback;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function loginRouteWithRedirect(redirectPath: string) {
|
||
|
|
return {
|
||
|
|
name: 'login' as const,
|
||
|
|
query: { redirect: redirectPath },
|
||
|
|
};
|
||
|
|
}
|