【发布时间】:2019-04-30 09:52:10
【问题描述】:
我需要将 firebase 身份验证令牌作为用户存储在 react native asyncstorage 中。这是我的代码。
loginUser = async (email, pw) => {
if (this.state.isConnected) {
if (email != '' && pw != '') {
try {
let user = fb.auth().signInWithEmailAndPassword(email, pw).catch((err) => {
alert('Invalid email or password');
});
this.storeUser(JSON.stringify(user))
console.log(user);
} catch (error) {
console.log(error);
}
}
}
}
storeUser = async (user) => {
try {
await AsyncStorage.setItem('User', JSON.stringify(user)).then(() => {
console.log("Success user");
})
} catch (e) {
console.log(e);
}
}
但它给了我这个错误
TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
谁能帮我解决这个问题?
【问题讨论】:
-
只需在调用
this.storeUser(JSON.stringify(user));时将 JSON.stringify(user) 更改为 user 即可 -
试过了。但不工作。仍然有同样的错误。
标签: javascript react-native firebase-authentication react-native-android