Untitled
unknown
plain_text
a year ago
614 B
10
Indexable
import React, { createContext, useState, useContext } from 'react';
const AuthContext = createContext();
export const AuthProvider = ({ children }) => {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const login = (username, password) => {
if (username === 'admin' && password === 'admin') {
setIsAuthenticated(true);
}
};
const logout = () => {
setIsAuthenticated(false);
};
return (
<AuthContext.Provider value={{ isAuthenticated, login, logout }}>
{children}
</AuthContext.Provider>
);
};
export const useAuth = () => useContext(AuthContext);
Editor is loading...
Leave a Comment