amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
423 stars 232 forks source link

How to auto sign in on page load? #71

Closed khinlatt closed 6 years ago

khinlatt commented 6 years ago

Hi,

So instead of calling auth.getSession() on button click, I would also like to put it on page load; this turns out to be a bad idea and it starts a loop going from the current site to aws login UI site back to current site and so on.

Perhaps, I'm not using this library correctly. I checked the auth object on page load but the user information (idToken) seems to be empty. I do see them in auth.storage and could use them; I wonder if this library already have methods for this use case? Could you please guide me on "signing in" and verifying the user on every page load?

Thank you very much!

lucasgao commented 6 years ago

auth.getCachedSession().isValid()

khinlatt commented 6 years ago

awesome thank you! That was what I was looking for.