How to refresh token on AWS Amplify using flutter

275 views Asked by At

So I have been trying to refresh my Auth token using flutter but without any success.

After a long time with the app on screen the token expires and all requests get rejected.

I called await Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey).fetchAuthSession(); and the response was the following:

CognitoAuthSession ({
  "isSignedIn": false,
  "userSub": "AWSErrorResult<String, SignedOutException> {\n  \"exception\": {\n    \"message\": \"No user is currently signed in\"\n  },\n  \"stackTrace\": null\n}",
  "userPoolTokens": "AWSErrorResult<CognitoUserPoolTokens, SignedOutException> {\n  \"exception\": {\n    \"message\": \"No user is currently signed in\"\n  },\n  \"stackTrace\": null\n}",
  "credentials": "AWSErrorResult<AWSCredentials, InvalidAccountTypeException> {\n  \"exception\": {\n    \"message\": \"No identity pool registered for this account\",\n    \"recoverySuggestion\": \"Register an identity pool using the CLI\"\n  },\n  \"stackTrace\": null\n}",
  "identityId": "AWSErrorResult<String, InvalidAccountTypeException> {\n  \"exception\": {\n    \"message\": \"No identity pool registered for this account\",\n    \"recoverySuggestion\": \"Register an identity pool using the CLI\"\n  },\n  \"stackTrace\": null\n}"
})

If I try to call await Amplify.Auth.getCurrentUser(); after calling fetchAuthSession() I get the response No user is currently signed in

So, AWS documentation is very shallow on this and it even mentions auto refresh stuff, but I can`t seem to use that https://docs.amplify.aws/lib/auth/advanced/q/platform/flutter/#token-refresh

0

There are 0 answers