1
I’m doing a get an api on Nodejs, only the result is coming back within a [[Promisevalue]], how do I access it directly?
With async and await it works, but when for it to authenticate on the route page it does not understand the "true" or "false"
Function that authenticates:
export const isAdmin = () => {
var result = api.get(`/role/listar/${role}`)
console.log(result)
if ("admin" !== "admin") {
console.log('ola')
return false
} else {
console.log("hello")
return true
}
}
Function that checks whether the user is true or false:
const AdminPrivateRoute = ({ component: Component, ...rest }) => (
<Route
{...rest}
render={props =>
isAdmin() ? (
<Component {...props} />
) : (
<Redirect to={{ pathname: "/", state: { from: props.location } }} />
)
}
/>
);
Note: I am using React and Xios.
"admin" !== " admin" will always return false, no?
– Davis Roberto
It was just to set an example.
– Gustavo Henrique