Home > OS >  AWS Cognito: tokens automatically get stored in local storage. How to save them in session storage i
AWS Cognito: tokens automatically get stored in local storage. How to save them in session storage i

Time:03-09

I am using AWS Amplify / AWS Cognito for my web app. It would automatically put tokens in browser's localStorage. This is the expected behavior of SDKs. It adds the tokens to local storage so user can use the app without logging in again after the session is closed and then restarted.

However, in my strange user scenario, I have to make my web app such that when user closes browser and re-opens it, the user must sign in again.

So instead of having the tokens saved in localStorage, I need to save them in sessionStorage of web browser.

How to do it nicely?

CodePudding user response:

This can be accomplished by passing window.sessionStorage into your auth configuration.

Auth.configure({ storage: window.sessionStorage })
  • Related