How can I alter the access token so that I can send a custom ID to my backend? #1291
Unanswered
LeunensMichiel
asked this question in
Help
Replies: 1 comment
-
Not sure but it looks like the JWT callback is what you are looking for? Use it to add the info you want to the JWT 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
-
Your question
How can I alter the access token so that I can send a custom ID to my backend?
What are you trying to do
So for a customer, we have to use Azure B2C to identify on the frontend/backend. We recieve a jwt token from azure with an oID, and NextAuth handles the insertion in our postgres database. We then pass the newly created info of the user (like the generated User ID) to the session object.
However, we have an entire GraphQL backend that handles all the logic, including middleware to verify a correct authentication. In the NextJs App, we send the accessToken from that said session-object to the Apollo-Client as a
Bearer {token}
authorization header. Normally, this header gets decrypted in the authorization middleware and we pass along the userId from the decoded token, so that we don't have to send the userId along with each network request.However, the decoded object only has the oid (account_provider_id), and I would like to add the userId of the session object to it as well. So right now I need to do a join on the user table every time I want info of that said user.
Is it possible to get that userId from the bearer/access token? And how would that work with a third party provider like Azure, and a custom backend with a custom database? And as a follow up question: Is it possible to remove our DB from NextAuth, and handle the logic ourselves in the backend?
I'm sorry if this might sound a bit dumb or confusing, I'm still learning! :)
Beta Was this translation helpful? Give feedback.
All reactions