JSON解析错误:aws放大state.user +领域数据库

时间:2019-06-01 12:43:13

标签: react-native realm aws-amplify

我正在将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 
     }); 
  }

0 个答案:

没有答案