furaiev / amazon-cognito-identity-dart-2

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
188 stars 114 forks source link

feat: try to refresh session if access token is null #219

Closed AndreiMisiukevich closed 1 year ago

AndreiMisiukevich commented 2 years ago

Currently, there is a case when the access token is null and getSession method fails with null reference exception.

We check idToken for null here if (await storage.getItem(idTokenKey) != null) { but we don't check accessToken for null which causes an exception inside CognitoJwtToken constructor (it calls decodePayload which forces unwrapping token value what is null)

So, the idea is

  1. Check that access token exists as well as idToken
  2. Try to refresh session in case either ID or Access token is null, but refresh token exists
furaiev commented 1 year ago

@AndreiMisiukevich thank you for your contribution, will be available as of 3.1.0