28 lines
796 B
Plaintext
28 lines
796 B
Plaintext
|
|
// AuthContext.jsx
|
||
|
|
import { createContext, useContext, useEffect, useState } from "react";
|
||
|
|
|
||
|
|
const AuthCtx = createContext(null);
|
||
|
|
export const useAuth = () => useContext(AuthCtx);
|
||
|
|
|
||
|
|
export function AuthProvider({ children }) {
|
||
|
|
const [hasAuthorizedSession, setHasAuthorizedSession] = useState(false);
|
||
|
|
const [isAuthResolved, setIsAuthResolved] = useState(false);
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
(async () => {
|
||
|
|
try {
|
||
|
|
// simulate or implement real check (localStorage/cookie/ping)
|
||
|
|
const token = localStorage.getItem("pozo_token");
|
||
|
|
setHasAuthorizedSession(!!token);
|
||
|
|
} finally {
|
||
|
|
setIsAuthResolved(true);
|
||
|
|
}
|
||
|
|
})();
|
||
|
|
}, []);
|
||
|
|
|
||
|
|
return (
|
||
|
|
<AuthCtx.Provider value={{ hasAuthorizedSession, isAuthResolved }}>
|
||
|
|
{children}
|
||
|
|
</AuthCtx.Provider>
|
||
|
|
);
|
||
|
|
}
|