我正在将Auth.signIn()用户信息存储到Realm Storage中,以便可以获取并发送OTP的用户确认信息。我收到JSON解析错误。
1。用户登录
export function authLogin(auth, props) {
Auth.signIn(auth.phone)
.then((user) => {
setStorageAuth(user);
props.navigation.navigate('Confirm', {
phone : auth.phone,
from: 'userlogin'
});
})
.catch((error) => {
alert(JSON.stringify(error));
})
}
2。确认OTP
export function verifyUsers(data, props) {
const promise = getStorageAuth();
promise.then(res => {
const user = JSON.parse(res[0].full) /* Parse error */
Auth.sendCustomChallengeAnswer(user, data.code)
.then(() => {
props.navigation.navigate('Thanks')
})
.catch(err => {
alert(JSON.stringify(err));
});
})
}
3。领域存储集
export const setStorageAuth = (data) => {
Realm.open({
schema: allSchema
}).then(realm => {
const dataString = JSON.stringify(data)
realm.write(() => {
realm.create('Auth', {
full: dataString
});
});
});
}
4。领域存储获得
export const getStorageAuth = () => {
return Realm.open({
schema: allSchema
}).then(realm => {
const data = realm.objects('Auth');
return data
});
}