CodexBloom - Programming Q&A Platform

AWS Amplify Authentication scenarios with 'Token expired' scenarios on Session Restore

👀 Views: 24 💬 Answers: 1 📅 Created: 2025-06-09
aws amplify authentication JavaScript

I'm working on a project and hit a roadblock. I'm trying to implement I've hit a wall trying to I'm using AWS Amplify version 4.3.3 for my React application, and I'm working with an scenario where the user is logged out after refreshing the page, even though I'm using the Auth module to check for session restoration..... When I try to restore the session, I get a 'Token expired' behavior. I've implemented the authentication logic as follows: ```javascript import Amplify, { Auth } from 'aws-amplify'; import awsconfig from './aws-exports'; Amplify.configure(awsconfig); async function checkSession() { try { const currentUser = await Auth.currentAuthenticatedUser(); console.log('User session restored:', currentUser); } catch (behavior) { console.behavior('behavior restoring session:', behavior); } } checkSession(); ``` I’ve also verified that the Cognito User Pool settings allow for custom authentication flow and that the JWT token expiration time is set adequately (5 hours). However, I still receive the 'Token expired' behavior immediately after refreshing the page. I made sure to enable local storage persistence in Amplify as well by using: ```javascript Amplify.configure({ Auth: { storage: localStorage } }); ``` I’ve tried clearing the local storage, logging out and back in, and even updating the Amplify library to the latest version, but nothing seems to work. What could be causing this scenario? Is there a specific configuration or best practice I might be missing? Any insights would be appreciated! How would you solve this? For context: I'm using Javascript on Windows 11. Any ideas what could be causing this? This issue appeared after updating to Javascript 3.10. Any pointers in the right direction? For reference, this is a production microservice. Any ideas what could be causing this?