Add attributes to user during authorization #764
-
Whenever I try to add more attributes to the user object in a custom authorization call, it seems I can only set the name, email and image. I would like to add an Id field based on a value retrieved in the call made to my external API during the call. I see the other way to set this is using the session callback, but this would involve an additional API call to get the info. Is there any way that more attributes can be added to the user object/session during the authorization process? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 19 replies
-
I was having the same issue, but it has been documented here https://next-auth.js.org/configuration/callbacks#session-callback:
In the jwt callback you can add attributes from the user object to the token object that you want to have during the session callback as the second parameter. |
Beta Was this translation helpful? Give feedback.
-
I had the same problem, but resolved it. Explanation here: |
Beta Was this translation helpful? Give feedback.
-
This is way more difficult than it needs to be. |
Beta Was this translation helpful? Give feedback.
-
I find it a bit confusing what is what in nextAuth, but what I did and it worked was:
in the CredentialsProviders:
|
Beta Was this translation helpful? Give feedback.
I was having the same issue, but it has been documented here https://next-auth.js.org/configuration/callbacks#session-callback:
In the jwt callback you can add attributes from the user object to the token object that you want to have during the session c…