Authstate, Login, Logout. Store, dispatch etc
This commit is contained in:
@@ -15,13 +15,12 @@ interface InitState {
|
||||
}
|
||||
|
||||
const initialState: InitState = {
|
||||
isLoading: false,
|
||||
isLoading: true,
|
||||
isAuthenticated: false,
|
||||
currentUser: null,
|
||||
};
|
||||
|
||||
const AuthProvider = (props: any) => {
|
||||
|
||||
const [store, setStore] = createStore(initialState);
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -35,16 +34,17 @@ const AuthProvider = (props: any) => {
|
||||
|
||||
onMount(async () => {
|
||||
await loadCurrentUser();
|
||||
setStore("isLoading", false);
|
||||
});
|
||||
|
||||
const setCurrentUser = (user: UserType) => {
|
||||
setStore("isAuthenticated", true);
|
||||
setStore("currentUser", user);
|
||||
setStore("isLoading", false);
|
||||
};
|
||||
const removeCurrentUser = () => {
|
||||
setStore("isAuthenticated", false);
|
||||
setStore("currentUser", null);
|
||||
localStorage.removeItem("current_user");
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user