forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProtectedRoute.tsx
More file actions
46 lines (39 loc) · 1.06 KB
/
Copy pathProtectedRoute.tsx
File metadata and controls
46 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use client';
import { useEffect } from 'react';
import { useRouter } from '@tschk/moonshine-next/navigation';
import Image from '@tschk/moonshine-next/image';
import { useAuth } from './AuthProvider';
interface ProtectedRouteProps {
children: React.ReactNode;
}
export function ProtectedRoute({ children }: ProtectedRouteProps) {
const { user, loading } = useAuth();
const router = useRouter();
useEffect(() => {
if (!loading && !user) {
router.push('/login');
}
}, [user, loading, router]);
// Show loading state while checking auth
if (loading) {
return (
<div className="min-h-screen flex items-center justify-center bg-bg-primary">
<div className="w-16 h-16 relative">
<Image
src="/logo.png"
alt="Omi"
fill
sizes="64px"
priority
className="object-contain animate-pulse"
/>
</div>
</div>
);
}
// Don't render children if not authenticated (will redirect)
if (!user) {
return null;
}
return <>{children}</>;
}