mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
improved password protection code
This commit is contained in:
15
traque-front/hook/usePasswordProtect.jsx
Normal file
15
traque-front/hook/usePasswordProtect.jsx
Normal file
@@ -0,0 +1,15 @@
|
||||
"use client";
|
||||
import { redirect, usePathname } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function usePasswordProtect(loginPath, redirectPath, loading, loggedIn) {
|
||||
const path = usePathname();
|
||||
useEffect(() => {
|
||||
if (!loggedIn && !loading && path !== loginPath) {
|
||||
redirect(loginPath);
|
||||
}
|
||||
if(loggedIn && !loading && path === loginPath) {
|
||||
redirect(redirectPath)
|
||||
}
|
||||
}, [loggedIn, loading, path]);
|
||||
}
|
||||
Reference in New Issue
Block a user