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 :
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 :
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With