Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only works with Debug JS Remotely on Android

I'm using AsyncStorage to store a JWT token from AWS, but there is an unexpected behavior that I want to clarified.

This is my current code :

const retrieveJwt = async () => {
  try {
    const value = await AsyncStorage.getItem('jwt');
    if (value !== null) {
      return value;
    }
    else{      
      let user = await Auth.currentAuthenticatedUser();
      let jwt = user.signInUserSession.accessToken.jwtToken;
      return jwt
    }
   } catch (error) {
     // Error retrieving data
     let user = await Auth.currentAuthenticatedUser();
      let jwt = user.signInUserSession.accessToken.jwtToken;
      return jwt
   }
}

// AppSync init
const client = new Client({
  url: AppSync.graphqlEndpoint,
  region: AppSync.region,
  auth:{
    type: 'AMAZON_COGNITO_USER_POOLS',
    jwtToken: async () => await retrieveJwt(),
  },
  disableOffline: true
})

When I'm running this application I got this :

  • Android real device without debugging : Failed
  • Android real device with Debug JS Remotely : Success
  • IOS simulator without debugging : Success
  • IOS simulator with Debug JS Remotely : Success

The problem is that it seems that the JWT Token is not retrieve neither by AsyncStorage nor by AWS Auth Class, and I can't resolve it because :

  1. I run on Android real device without debugging : doesn't work.
  2. I run on Android with debugging : it works.

So I can't debug to see what is wrong because it works when I try to debug on Android.

Hope someone could help me.

like image 507
Jobel Avatar asked Aug 24 '18 09:08

Jobel


1 Answers

I had a similar issue here.

My problem was not when I've read value from the AsyncStorage, but rather, when I've tried to save some value.

When I used the remote debugger everything did work fine, but without it an Error appeared.

The solution was to convert the value to string before save them into the storage.

like image 159
raistlinthewizard Avatar answered Oct 14 '22 17:10

raistlinthewizard