I was doing an authorization for my react app, and I've made a redirect from /auth
route if user is logged in. After logout, the redirect still works, even thought the isLoggedIn
value from Api is changed for sure(checked with console.log
to be sure)
I dont really know why, so I only tried to change some of Api methods, the isLoggedIn was a get attribute of an object before, now it's function.
function Auth(){
return (
<div>
<Header theme="light"/>
<Switch>
{Api.Auth.isLoggedIn() && <Redirect to={routes.home}/>}
<Route path={routes.login} component={Login}/>
<Route path={routes.register} component={Register}/>
</Switch>
</div>
);
}
Api:
isLoggedIn() {
console.log(this._token, !!this._token); // test, returns false everytime, but redirect works...
return !!this._token;
},
logout(){
this._token = null;
this._axiosSetToken('');
try {
window.localStorage.removeItem('token');
} catch (e) {
console.error(e);
}
}
I have one more thing that are using the same login check(displaying or now profile link with avatar in header, but there it works fine and login button appears.
The thing work okay after F5(page reload), and it doesn't matter if I reloaded the page before logout, or after - it will work.