私は何らかの認証を行う反応ネイティブのアプリケーションを持っています。Promise return undefined AsyncStorage
トークンが有効期限切れでないかどうかをチェックする次のコードがあります。
export const isLogged =() => {
AsyncStorage.getItem('@token')
.then(token => {
if (typeof token !== 'undefined') {
if (tokenExpired(token)) {
return false
}
return true
}
return false
})
.catch(error => {
return false
})
}
しかし、私のコードで私がない場合:
let isUserLogged = isLogged()
console.log(isUserLogged) // -> returns undefined, but should return true because the token is there and its not expired.
誰が、なぜそのこのように、私が何か間違ったことをいくつかのアイデアをやっていますか?
あなたは別の 'then'ステージを連鎖させてそこにチェックインする必要があります。 – Redu