Files
traque/traque-front/hook/usePasswordProtect.jsx
Sébastien Rivière d25dcfcbc1 Corrections
2025-06-25 17:52:59 +02:00

17 lines
496 B
JavaScript

"use client";
import { redirect, usePathname } from "next/navigation";
import { useEffect } from "react";
export default 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]);
}