amazon-archives / aws-cognito-angular-quickstart

An Angular(v5)-based QuickStart single-page app utilizing Amazon Cognito, S3, and DynamoDB (Serverless architecture)
https://cognito.budilov.com
Apache License 2.0
689 stars 304 forks source link

How to implement *Remeber Me* option using sdk? #119

Closed webcat12345 closed 4 years ago

webcat12345 commented 6 years ago

I am trying to implement Remeber Me option for authentication workflow. I use below flow.

Current authentication flow

  1. If Remember me option is checked then save token and jwt token(specially do this because I need some other user info such as groups and roles) to cookie with expiration date. (ex : 5 days )
  2. Auth guard (that is checking all routing changes even if root routing) will check token(not jwt) first
  3. If cookie is empty then redirect to Login page.
  4. If cookie exists then check session(using function of sdk), session is invalid then redirect to Login page.
  5. If session is valid then update jwt(not token) and guard returns true.

I think it seems fine, but I am getting some unexpected errors, not often but once 1 hour has passed (actual session expired).

Questions

  1. Do I have to update token as well? At step 5.
  2. Is this.cognitoUtil.getCurrentUser(); asynchronous function?
  3. What will be returned from cognitoUser.getSession() if session is expired?
  4. If Ques 3 returns session (even if it is valid or invalid), what is the returning value of session.isValid()?
webcat12345 commented 4 years ago

https://stackoverflow.com/questions/47066681/how-to-implement-remember-me-option-using-amazon-cognito-sdk