-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check token expiry? #108
Comments
Use ‘user.jwt().then()’ to auto refresh the token. |
Thanks @bcomnes . What does |
Sorry for the brevity, was mobile when I responded. It will automatically refresh the JWT token with the existing login if it has expired. The user objects in the widget are generated by https://github.com/netlify/gotrue-js internally and share the same API. |
Thank you @bcomnes I am trying to 'protect' certain pages with login using client side router (vue-router). As of now, roughly doing something like below
On each route transition, check if valid userToken exists or not (using the This works perfectly for loggedIn or loggedOut scenarios, where the But this does not take care of If What I am looking for is more of: on the client side itself determine if token is expired or not. Something like No renewal. Just a boolean true/false return value. So that user will be force "logged out" / forced to login for stale tokens. Also, is there a way to configure the token timeout / expiry? |
The JWT has an expiration encoded in it. The expiration is also in the User.token object. |
Yeah thats correct, sorry for the delayed response on my end, I lost track of a bunch of github notifications over the holidays. |
Thank you. I see the token object has below fields:
It has For example, this The other field, Any example code or docs would be greatly helpful. Thank you again for your insights and help. Or any link to the code on how the server validating the token would also be helpful. I can try copy that code and make relevant changes to make it work on client side. |
I am trying to use
Would this be correct? The |
This is how it works internally: https://github.com/netlify/gotrue-js/blob/master/src/user.js#L62-L68 |
Any method to check if the token is still valid or expired? So that we can open the login dialog again (if the stored token is expired)
The text was updated successfully, but these errors were encountered: