Ошибка синтаксического анализа JSON: AWS Ampify State.user + Realm База данных - PullRequest
0 голосов
/ 01 июня 2019

Я храню информацию о пользователе 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.Realm Storage получить

  export const getStorageAuth =  () => {
   return Realm.open({
     schema: allSchema
     }).then(realm => {
       const data = realm.objects('Auth');
       return data 
     }); 
  }
...