blob: 8dd191ce1180a364ffc775dbb8d1fca57d276d84 (
plain)
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
|
import { useAtomValue } from "jotai";
import type { ReactNode } from "react";
import { Redirect } from "wouter";
import { authLoadingAtom, isLoggedInAtom } from "../atoms";
interface Props {
children: ReactNode;
}
export function ProtectedRoute({ children }: Props) {
const isLoggedIn = useAtomValue(isLoggedInAtom);
const isLoading = useAtomValue(authLoadingAtom);
if (isLoading) {
return (
<div className="flex justify-center items-center min-h-screen">
Loading...
</div>
);
}
if (!isLoggedIn) {
return <Redirect to="/login" />;
}
return <>{children}</>;
}
|