Confirm user's token on navigation, clear user cache properly

This commit is contained in:
Tanner Collin 2020-02-04 08:32:01 +00:00
parent 26845a5921
commit 3565bddf8d

View File

@ -40,14 +40,14 @@ function App() {
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err);
setUser(false); setUserCache(null);
}); });
}, [token, refreshCount]); }, [token, refreshCount]);
function logout() { function logout() {
if (yousure) { if (yousure) {
setTokenCache(''); setTokenCache('');
setUserCache(false); setUserCache(null);
setYousure(false); setYousure(false);
history.push('/'); history.push('/');
window.scrollTo(0, 0); window.scrollTo(0, 0);
@ -56,6 +56,18 @@ function App() {
} }
} }
useEffect(() => {
user && requester('/ping/', 'POST', token, {})
.then()
.catch(err => {
console.log(err);
if (err.data && err.data.detail === 'Invalid token.') {
logout(); // You Sure?
logout();
}
});
}, [history.location]);
return ( return (
<div> <div>
<div className='content-wrap'> <div className='content-wrap'>