Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito force refresh session

I'm running into some problems when I attempt to refresh my session tokens, (Access, Id, Refresh). I have already read this question and the answer has helped me understand what is going on some. But I feel what I am trying to do isn't quite what getSession is for.

I am attempting to implement a session expiration message (done) that allows the user to extend their session (refreshes the tokens). From what I gather about getSession(), it returns either the old tokens, if they are still valid, or new tokens if they are not valid. Please correct me if I am wrong there.

I am attempting to give the user new/refreshed tokens every time they click on extend session. For dev purposes, I have a button which then displays the message with the extend session button. The tokens I receive when I call getSession() are the old ones, but I want them to be new ones.

So basically, nullifying the old session and giving them a new one.

My questions are:

  1. Am I missing some understanding about getSession(), as previously mentioned?
  2. Can I give the user new session tokens (Access, Id, Refresh)?
  3. Can I do #2 without having the user sign in again?

Thank you.

EDIT 1: It may help to know that I am not using any Federated Identities.

like image 739
Hypnic Jerk Avatar asked Feb 05 '23 09:02

Hypnic Jerk


1 Answers

You can call cognitoUser.refreshSession. I've found a reasonable example for you over here:

Sample code: how to refresh session of Cognito User Pools with Node.js and Express

Look for the method called checkTokenExpiration, it explains perfectly well what you have to do to refresh the session.

like image 174
Danny Hoek Avatar answered Feb 08 '23 10:02

Danny Hoek