Fetching data *once* and storing it in session #2893
Unanswered
nkalupahana
asked this question in
Help
Replies: 1 comment
-
If you need to add something only at the beginning of a session, check out the docs: https://next-auth.js.org/configuration/callbacks#jwt-callback |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When a user signs in, I'd like to fetch some sensitive information about them from a database (note: expensive operation) and store it in their server-side session. That way, in future requests (for the whole duration they're signed in), we can get that data directly from the user's session instead of having to do that expensive operation every time.
How would you go about doing this with next-auth's sessions? I tried putting the data in the
jwt
callback, but that callback seems to get called every time a page is loaded, so that expensive operation gets repeated constantly. I just want it to be run when the user signs in, stored, and then never again.Beta Was this translation helpful? Give feedback.
All reactions