【发布时间】:2021-09-06 13:23:34
【问题描述】:
所以,我正在尝试获取我的减速器的 JWT 令牌 INITIAL_STATE。
我正在使用 'expo-secure-store' 包作为使用 expo 的商店令牌
但是当我尝试获取令牌时,它返回的是一个承诺而不是令牌值,如下所示:
AuthUser: Promise {
"_U": 0,
"_V": 1,
"_W": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo3LCJ1c2VybmFtZSI6InNocmVleWFjaEBzYXR2aXguY29tIiwiZW1haWwiOiJzaHJlZXlhY2hAc2F0dml4LmNvbSI",
"_X": null,
}
这是我获取令牌的代码:
import * as SecureStorage from 'expo-secure-store';
const _retrieveData = async () => {
try {
const data = await SecureStorage.getItemAsync('token');
return data;
} catch (error) {
console.log(error);
}
};
const INIT_STATE = {
loader: false,
alertMessage: '',
successMessage: '',
showMessage: false,
initURL: '',
authUser: _retrieveData().then((token) => token),
tempAuth: '',
currentScreen: 0,
showSuccessMessage: false,
currentUser: null,
sendOTP: false,
};
【问题讨论】:
标签: react-native expo