-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fetchAuthSession() returning {"name":"Unknown","underlyingError":{}}
#13718
Comments
Hey @cwomack , thanks for picking up. Happy to jump a call to help triage further if that helps. Also if you have any other workarounds that would be super helpful i.e. do we just directly hit the cognito endpoints in order to refresh the token? if you want to check out our app its https://runna.com |
Hello, @walterholohan and sorry to hear you've got users running into this. It may be hard to identify why this is happening with the information provided due to these types of unknown errors get asserted in every Auth API (see here). It's odd that the Can you provide the stack trace of the error if you have it? Or possibly get more details from the network request when this happens? Are you able to access the |
Thanks for the reply Chris. I will add in more debugging logs to see if I can expose more of the error. In the meantime, should I go pure vanilla in order to refresh the access tokens? i.e.
|
@walterholohan, we're hesitant to make any recommendations to manually start making HTTP Post requests to the Cognito endpoints without seeing the debugging logs/errors. Do you know if any of the users that experience this also have network issues or slow connections? |
Yep I can see in Sentry a few slow network/no network requests. In our app, if no network connection then we still want the user to be logged in and we show them cached content which we persist to local storage. To determine if they are logged in we check async storage to see if a refresh token is present. Do you think fetchAuthSession is clearing async storage if no network or if the refresh request fails? I can see from logs in sentry it usually when a user opens app more than 24 hours since last session (i.e. access token is 24 hours) so fetchAuthSession I presume would try refresh the token under the hood |
@walterholohan, Just to summarize my understanding of what's happening so far so we can attempt to reproduce on our side better:
That look proper for reproduction? And are you able to reproduce this yourself locally at all? If so, can you verify by inspecting your async storage that the tokens are not there? |
Hey @cwomack sorry about the delay. I added some extra logs to our app and was just waiting to see what came back. Below is what I found Sentry shows that there is some timeout or network issue when calling the cognito endpoint After this fetchAuthSession() will return the below error
After this on some occasion's the tokens will be removed from async storage. I have tried to replicate locally but was unable too, but it seems some users get the |
@cwomack we seem to be getting a lot of people now where the token is failing to refresh, even though our refresh token expiry is set to 3 years and we have only been using Cognito for 1 year. Just for context, we fire off quite a few API requests when the app launches, and on each request we check if the token has expired or not. Do you think if we fired As mentioned above is there any other primitive way of refreshing the token? Or happy to jump on a 30 minute call either and I can show you what we do in the app? |
@walterholohan, it sounds like there's a possibility this is related to the Quota Limits in Cognito. While the Can you help us verify this by clarifying how many calls are made to |
So at one stage we were making the fetchAuthSession() before every API call thinking that it would just return the
FYI we have no server logs as we use AWS AppSync and use cognito as the authentication source |
@walterholohan, thanks for the follow up. Wanted to check in and see if the refactoring has helped at all from getting the errors (and possibly confirming that it was the quota limits from Cognito that were the culprit). Let us know if you're still running into this? |
@cwomack unfortunately we are still getting user's whose tokens are getting wiped from async storage. It seems like if we hit I checked our Cognito quota in AWS but we were hitting now limits. Does each user have a limit too? |
@MaximilianSchon the upgrade to v6 was also main culprit for us |
We also are experiencing issues with Calling a code similar to this before every request seems to perform odd when a users was inactive for a long period of time.
With a cookie storage similar
The way we have constantly been able to reproduce this was to set the id token and access token lifetime to 5 minutes. Comparing this to another project that runs on: Current workaround is to refresh the page on the first |
@stmihai1337, appreciate the additional context and follow up here. To your point about the ID and Access tokens being set to have a TTL of 5 min, then awaiting 5-6 min to call While this might reproduce similar (if not the same) issue that @walterholohan is experiencing, we're still looking into this to see if there's either improvements to be made on how I'm following up with @walterholohan outside of Github to review this, but we'll comment back on this issue once we've met and have more details. |
@stmihai1337, one more question for you... are you using React Native or Next.JS? |
@walterholohan, we believe we've identified what the root cause is here. Can you please upgrade to the latest version of Amplify (anything v6.6.7+) and let us know if the issue gets resolved? We're currently on v6.8.0, so simply upgrading to latest would work as well. (I'm going off the assumption you're still on a version lower than v6.6.7 based on the environment info when this issue was opened). |
@walterholohan, have you had a chance to upgrade to see if this persists? |
Hey @cwomack , we pushed a new version of the app live today so we should know more within the coming week. |
Thanks @walterholohan please keep us updated. |
Hey @HuiSF @cwomack we seem to be now getting a new issue. When trying to refresh a token we are getting the error |
@walterholohan this exception happens only when refresh token is not presented in the local store when the library attempts the refresh token step. Refresh token is not being issued when using federated sign in with implicit grant flow. End user needs resign in to retrieve access token instead refreshing it. Is this something you are using? |
Thanks @HuiSF. As I am aware all social login's should issue a refresh token, well that's how I thought we setup it up and also from testing on my local simulator I can see that there is a refresh token in storage upon signing. Do you think this is part of the underlying issue where the refresh token is getting removed from async storage by the amplify library? |
@walterholohan, thanks for following up here. It looks like the behavior that you're referencing might be related to what's captured in this comment from issue #14033. We have a related feature request and PR surrounding this race condition that we are looking into and will follow up with soon, but for the time being can you look at what's described in these @walterholohan and let us know if they capture the new error you're running in to? |
thanks @cwomack , yeah its seems like the issue has got a lot worse for us since upgrading i.e. the tokens keep getting cleared in async storage. And it seems to relate to the issue's you reported above |
@walterholohan, thanks for the update. It sounds like the original scope of what this issue was capturing was resolved in v6.6.7 (or higher), and the persisting problem is more related to the issues linked in this comment above. We'll close this issue out for now, but can reopen if the We'll follow up on those issues for progress from here since the PR and related FR are being reviewed internally at this point. |
Thanks a million for all your help @cwomack. Hopefully the other issue can be solved as soon as possible |
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
Other
Environment information
Describe the bug
In our app we call
fetchAuthSession()
when the app load so that we can get the latestidToken
toke to use with our API requests. However randomly for some users they get the error{"name":"Unknown","underlyingError":{}}
which then results in theidToken
token getting removed from async storage.Expected behavior
The user is logged in, and a valid
idToken
should be returnedReproduction steps
await fetchAuthSession()
to get latest token or refresh the tokenawait fetchAuthSession()
will throw an error randomly for some users (FYI we have over 200,000 MAU's)Code Snippet
Log output
aws-exports.js
No response
Manual configuration
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: