How do I form this function to 'wait' for stateUserInfo
to be surely filled first, before proceeding to setting the stateToken
(trigger to conditionally render to my HomeScreen)?
async function submitLogin() {
try {
const data = await axios.post(apiAuth, {username: email, password: password, auth: auth})
const jwt = data.data.data.jwt
console.log(jwt)
getUserDetails(jwt)
}
catch (err) {
console.log(err)
}
}
async function getUserDetails(jwt) {
const data = await axios.get(apiValidate+'&JWT='+jwt)
setTimeout(function() {
setStateUserInfo(data.data)
}, 4000);
//go to HomeScreen BUT FIRST WAIT FOR stateUserInfo!!!
setStateToken(jwt)
}