mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
refactor(frontend): hook for checking that user is logged in
This commit is contained in:
parent
be38c383ef
commit
8ecfe57661
8 changed files with 37 additions and 38 deletions
16
frontend/src/hooks/use-auth-protection.tsx
Normal file
16
frontend/src/hooks/use-auth-protection.tsx
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useAuth } from "./use-auth";
|
||||
|
||||
export function useAuthProtection() {
|
||||
const { user } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const requireUser = useCallback(async () => {
|
||||
if (!user) {
|
||||
navigate("/");
|
||||
}
|
||||
}, [user, navigate]);
|
||||
|
||||
return { requireUser };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue