mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
15 lines
482 B
JavaScript
15 lines
482 B
JavaScript
"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]);
|
|
} |