I am making a react app and I am stuck on the islogged in part.
I have a fairly simple privateRoute system which is set up like so.
<Route {...rest} render={props => (
isLogin() ?
<Component {...props} />
: <Redirect to="/" />
)} />
The problem starts when trying to return isLogin()
I connect to my api with a token i obtain from the login screen and i am getting back the correct status code however no matter what I do it never returns true or false. I get the console.log printed but thats as far as it goes.
import axios from "../api/axios";
export const isLogin = () => {
axios({
method: "POST",
url: "/userinfo",
headers: { Authorization: `Bearer ${token}` }
}).then(res => {
if(res.status === 200){
console.log("connected")
return true
}else{
return false
}
}).catch(() => {
return false
});
}
Honestly stumped on how to get around this as I am fairly new.