fix: RequireAuth no fallback UI, client-only check
This commit is contained in:
parent
1990b5c99d
commit
87a741540b
1 changed files with 2 additions and 3 deletions
|
|
@ -148,15 +148,14 @@ export function useAuth() {
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RequireAuth(props: ParentProps<{ fallback?: string }>) {
|
export function RequireAuth(props: ParentProps) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
const fallback = props.fallback || '/login';
|
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
if (!auth.isAuthenticated()) {
|
if (!auth.isAuthenticated()) {
|
||||||
navigate(fallback, { replace: true });
|
navigate('/login', { replace: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue