improved password protection code

This commit is contained in:
Quentin Roussel
2024-03-28 20:47:05 +01:00
parent ba7abe3b3c
commit 27e5a6615a
14 changed files with 137 additions and 111 deletions

View 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]);
}