login
This commit is contained in:
@@ -3,13 +3,13 @@ import { createContext, useState, useContext } from 'react';
|
||||
const AuthContext = createContext();
|
||||
|
||||
const AuthProvider = ({ children }) => {
|
||||
const [role, setRole] = useState(localStorage.getItem('role') ?? 'user');
|
||||
const [user, setUser] = useState(localStorage.getItem('user'));
|
||||
|
||||
return <AuthContext.Provider value={{ role, setRole }}>{children}</AuthContext.Provider>;
|
||||
return <AuthContext.Provider value={{ user, setUser }}>{children}</AuthContext.Provider>;
|
||||
};
|
||||
|
||||
const logout = () => {
|
||||
localStorage.removeItem('role');
|
||||
localStorage.removeItem('user');
|
||||
window.location.href = '/auth';
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useAuth } from './auth-provider';
|
||||
|
||||
const GrantAccess = ({ roles, children }) => {
|
||||
const { role } = useAuth();
|
||||
return roles.includes(role) ? children : null;
|
||||
const { user } = useAuth();
|
||||
return roles.includes(user) ? children : null;
|
||||
};
|
||||
|
||||
export default GrantAccess;
|
||||
|
||||
Reference in New Issue
Block a user