-
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 returns object with undefined values #13648
Comments
Hello @sgoy-suzutatsu. Sorry to hear you are experiencing issues with the library. The You can listen to the |
Going to attempt to add a translation to the issue here to help us @sgoy-suzutatsu. Let me know if this is correct: I apologize if my explanation is unclear due to language issues. background Using Next.js for static generation However, the actual behavior is different. Approximately once every hour (with some variation), fetchAuthSession may return an empty object when the token is refreshed. I have attached the relevant code for your reference. I am logging token expiration events, but interestingly these logs suggest that the token is being successfully retrieved. It's worth noting that the failed tokens in these logs look the same across different dates. The attached image token has been hashed to protect its original format. While searching for a similar issue, I found several reports of similar phenomena, but none that exactly matched our environment. |
@sgoy-suzutatsu, it looks like you're on v6.0.23 of Amplify. Just to see if we can determine if this was an older bug that was fixed, can you see if upgrading to the latest version resolves the issue (v6.4.3 currently at the time of this comment)? If not, can you take a look at #13486 to see if that describes what you're experiencing? And can you clarify if you are seeing this behavior under the following scenarios:
|
@cwomack @israx Regarding the reproduction of the session expiring within 24 hours, it seems to occur when the same application is used on multiple devices simultaneously. Our understanding is that different tokens should be issued for each device since they are separate instances. However, could there be some form of token conflict or interference occurring due to this multi-device usage? Any insights into this aspect of the issue would be greatly appreciated. |
|
@cwomack @israx
Does this mean that the refresh token is not functioning correctly and the token is not being refreshed after the 1-hour expiration period? Even after updating Amplify to the latest version, the same issue seems to be occurring. |
@sgoy-suzutatsu, thank you for the additional logs and follow up here. If you're receiving the |
still havent resolve, i have similar problem with next js app router + aws-amplify package, alreadt upgraded to the latest version, somehow the idtoken is undefined, i need to use it to fetch the api :( |
@farhan-helmy, are you able to provide more details on how you're TTL settings are configured within your app or provide a screenshot/full log of the corresponding failing network requests to the Cognito endpoint? If you're experiencing the same errors with undefined values, we can continue it within this issue or feel free to open a new one yourself to capture your environment details. But are you also experiencing this with the Auth category or another? Any additional information on the API's you're calling when this happens would be appreciated. |
@israx @cwomack is this still the case if all the cognito tokens are in localStorage? It seems like I'm getting undefined values with await fetchAuthSession even though my localStorage has all the valid tokens |
@thejasonxie, the default behavior for token storage in Amplify is to use |
Also wanted to follow up with @farhan-helmy and @sgoy-suzutatsu. There were follow up questions/comments above, but let us know if you're still blocked here! |
Yes i only want to use defaults. For more context, I was trying to make a wrapper package around aws-amplify and I thought this would work since it should be checking localStorage by default but it seems even when strictly configured for localStorage, the issue is still the same. |
@thejasonxie, just to ensure we can separate the OP's issue from yours here... would you mind opening up a new issue so we can capture your environments information, code that reproduces this, etc? Given that you're using a wrapper package, we might need more context and steps to reproduce. |
@sgoy-suzutatsu, we'll close this issue as we have not heard back from you. If you are still experiencing this, please feel free to reply back and provide any information previously requested and we'd be happy to re-open the issue. Thank you! |
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
REST API
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
Describe the bug
amplify in aws and using nextjs with existing endpoints.
English is not good enough.
言葉の問題で説明が不明瞭であれば申し訳ない。
背景
アプリケーションにログインした後、ポーリングが開始され、1分ごとに新しい情報がフェッチされます。このプロセスの間、トークンを利用するために毎回
fetchAuthSession
が呼び出されます。トークンの有効期限が1時間後、リフレッシュトークンの有効期限が24時間後であることを考えると、理論的には24時間継続してアプリケーションを使用できるはずです。しかし、実際の動作は異なります。およそ1時間に1回(変動はありますが)、トークンのリフレッシュのタイミングで、
fetchAuthSession
が空のオブジェクトを返すことがあります。参考までに関連するコードを添付しておきます。トークンの有効期限切れイベントをログに記録していますが、興味深いことに、これらのログはトークンが正常に取得されていることを示唆しています。これらのログの失敗したトークンは、異なる日付にまたがって同じように見えることは注目に値します。添付画像のトークンは、元の形式を保護するためにハッシュ化されている。
同じような問題を検索していたところ、同じような現象に関する報告がいくつか見つかりましたが、私たちの環境と完全に一致するものはありませんでした。
Expected behavior
The expected behavior is that fetchAuthSession should continue to return tokens and other information as long as it's within the 24-hour period.
Reproduction steps
Steps to Reproduce:
Note: This procedure does not guarantee 100% reproducibility.
The issue may be more likely to occur when multiple users are utilizing the same Cognito information.
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
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: