UNPKG

@duongtrungnguyen/next-helper

Version:
20 lines 583 B
"use client"; import { useContext, useEffect } from "react"; import { AuthContext } from "./context"; import { libConfig } from "../configs"; const useAuth = () => useContext(AuthContext); function useProtectedRoute() { const { state } = useAuth(); const { isAuthenticated, isLoading } = state; useEffect(() => { if (!isLoading && !isAuthenticated) { window.location.href = libConfig.auth.endpoints.login; } }, [isAuthenticated, isLoading]); return { isLoading, isAuthenticated }; } export { useAuth, useProtectedRoute }; //# sourceMappingURL=hooks.js.map