Authentication updates
This commit is contained in:
parent
98b1daa7d3
commit
3015c98246
15 changed files with 657 additions and 165 deletions
20
hooks/useCheckAuth.ts
Normal file
20
hooks/useCheckAuth.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export function useCheckAuth() {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
async function check() {
|
||||
const res = await fetch("/api/auth/check");
|
||||
console.log(res);
|
||||
if (!res.ok) {
|
||||
console.log("Invalid tokin");
|
||||
router.push(
|
||||
"/auth?callbackUrl=" + encodeURIComponent(window.location.pathname),
|
||||
);
|
||||
}
|
||||
}
|
||||
check();
|
||||
}, [router]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue