ci/woodpecker/pr/ci Pipeline was successful
Ports the legacy Next settings page (profile/appearance/notifications/ providers tabs) and admin page (user management + system health) into spa/pages as faithful ports, replaces the /settings and /admin route placeholders, and adds a route-level AdminGuard mirroring the legacy AdminRoleGuard semantics (unauthenticated -> /login, non-admin -> /). Legacy app/ tree untouched; removal stays in P5 per the increment map.
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import type { ReactElement } from 'react';
|
|
import { Navigate, Outlet } from 'react-router-dom';
|
|
import { useSession } from '@/lib/auth-client';
|
|
|
|
export function GuestGuard(): ReactElement {
|
|
const { data: session } = useSession();
|
|
|
|
return session ? <Navigate to="/chat" replace /> : <Outlet />;
|
|
}
|
|
|
|
export function AuthGuard(): ReactElement {
|
|
const { data: session, isPending } = useSession();
|
|
|
|
if (isPending) {
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center">
|
|
<div className="text-sm text-text-muted">Loading...</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return session ? <Outlet /> : <Navigate to="/login" replace />;
|
|
}
|
|
|
|
export function AdminGuard(): ReactElement {
|
|
const { data: session, isPending } = useSession();
|
|
|
|
if (isPending) {
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center">
|
|
<div className="text-sm text-text-muted">Loading...</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!session) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
const user = session.user as typeof session.user & { role?: string };
|
|
|
|
return user.role === 'admin' ? <Outlet /> : <Navigate to="/" replace />;
|
|
}
|