From 2a9c6cf6a1ee7975766f0bb35e62fc2d225a8abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Tue, 14 Jun 2022 11:39:43 -0300 Subject: [PATCH] Add logout logic --- src/context/auth.js | 9 +++------ src/screens/Home/index.js | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/context/auth.js b/src/context/auth.js index e5c46b5..e263d89 100644 --- a/src/context/auth.js +++ b/src/context/auth.js @@ -29,12 +29,11 @@ function AuthProvider(props) { async function bootstrapUser() { const user = window.localStorage.getItem('$USER'); if (user) { - console.log(user); setState({ status: 'success', user: JSON.parse(user), error: null }); } } bootstrapUser(); - }, [setState]); + }, []); const login = (email, password) => { setState({ ...state, status: 'pending' }); @@ -51,10 +50,8 @@ function AuthProvider(props) { }; const logout = () => { - setState({ ...state, status: 'pending' }); - return getUser().then(() => - setState({ status: 'success', user: null, error: null }) - ); + setState({ status: 'success', user: null, error: null }); + window.localStorage.clear(); }; return ; diff --git a/src/screens/Home/index.js b/src/screens/Home/index.js index cf56389..190a837 100644 --- a/src/screens/Home/index.js +++ b/src/screens/Home/index.js @@ -1,12 +1,15 @@ +import { useAuthState } from '../../context/auth'; import { useUser } from '../../context/user'; function Home() { const { isPending, classrooms } = useUser(); + const { logout } = useAuthState(); return (

Página inicial

+ {isPending &&

Loading...

}
);