26 lines
531 B
React
26 lines
531 B
React
|
import { createContext, useContext, useState } from "react";
|
||
|
|
||
|
const AuthContext = createContext();
|
||
|
|
||
|
export function AuthProvider({ children }) {
|
||
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||
|
|
||
|
const login = () => {
|
||
|
setIsAuthenticated(true);
|
||
|
};
|
||
|
|
||
|
const logout = () => {
|
||
|
setIsAuthenticated(false);
|
||
|
};
|
||
|
|
||
|
return (
|
||
|
<AuthContext.Provider value={{ isAuthenticated, login, logout }}>
|
||
|
{children}
|
||
|
</AuthContext.Provider>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
export function useAuth() {
|
||
|
return useContext(AuthContext);
|
||
|
}
|