Skip to content
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

Clarification: Do I have to call user.jwt() before every back-end call #75

Open
willdkp opened this issue Mar 26, 2020 · 4 comments
Open
Labels

Comments

@willdkp
Copy link

willdkp commented Mar 26, 2020

I am passing the a JWT token to a lamda function on netlify. Currently I am calling auth.currentUser().jwt() before each fetch to the lamda function endpoint. Is it possible to call .jwt() once after a user logs in and cache it somewhere in my react app? Or is it needed to do this just-in-time of when I am going to use it.

Will the token expire or go stale? If so when?

@luukdv
Copy link

luukdv commented Jul 29, 2020

In my experience, it will go stale without explicitly calling jwt() each time.

@erezrokah
Copy link
Contributor

erezrokah commented Jul 29, 2020

In my experience, it will go stale without explicitly calling jwt() each time.

This ⬆️

But the jwt method will only refresh the token when needed, otherwise it returns the current one:

if (forceRefresh || expires_at - ExpiryMargin < Date.now()) {

However, Netlify functions has an identity context (with an elevated permissions token) set for them so you might not need to send the token at all. See example:
https://github.com/netlify/gotrue-js#get-a-user

@SteveALee
Copy link

However, Netlify functions has an identity context (with an elevated permissions token) set for them so you might not need to send the token at all. See example:
https://github.com/netlify/gotrue-js#get-a-user

This is critical information and needs documenting for securing Functions in a production context

@jon-sully
Copy link

Posting this for others who may come here; this extensive discussion on Netlify Community should answer plenty of questions around using Netlify Identity with Netlify Functions and joining the two

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants