mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-03-23 10:45:08 +00:00
feat: add support for email verification (#1223)
This commit is contained in:
@@ -2,7 +2,8 @@ import type { User } from '$lib/types/user.type';
|
||||
|
||||
// Returns the path to redirect to based on the current path and user authentication status
|
||||
// If no redirect is needed, it returns null
|
||||
export function getAuthRedirectPath(path: string, user: User | null) {
|
||||
export function getAuthRedirectPath(url: URL, user: User | null) {
|
||||
const path = url.pathname;
|
||||
const isSignedIn = !!user;
|
||||
const isAdmin = user?.isAdmin;
|
||||
|
||||
@@ -19,7 +20,8 @@ export function getAuthRedirectPath(path: string, user: User | null) {
|
||||
const isAdminPath = path == '/settings/admin' || path.startsWith('/settings/admin/');
|
||||
|
||||
if (!isUnauthenticatedOnlyPath && !isPublicPath && !isSignedIn) {
|
||||
return '/login';
|
||||
const redirect = url.pathname + url.search;
|
||||
return `/login?redirect=${encodeURIComponent(redirect)}`;
|
||||
}
|
||||
|
||||
if (isUnauthenticatedOnlyPath && isSignedIn) {
|
||||
@@ -29,4 +31,6 @@ export function getAuthRedirectPath(path: string, user: User | null) {
|
||||
if (isAdminPath && !isAdmin) {
|
||||
return '/settings';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user