@duongtrungnguyen/next-helper
Version:
Helper library for Next.js 15
20 lines • 583 B
JavaScript
"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