NextAuth exposing next-auth.session-token to token.user object #9938
Unanswered
agoyal1999
asked this question in
Help
Replies: 1 comment
-
inside your auth.ts add this
also inside your IUser interface add
and make your callback something like this
|
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
-
After trying multiple ways and going through numerous articles and videos, I am still not able to solve a trivial issue. I have used nextAuth in my fullstack next app. I am using NextAuth v4 and nextJS v14. I tried to implement a the credential provider for my app, while the whole authentication works smoothly, I want to be able to set the accessToken in my returned session object so that I can use it to make API calls from my frontend to my server due to the token auth mechanism I have set for my APIs. Right now, I manually copy paste the token from my browser cookies and then make calls to my APIs. This works, but I want to be able to extract it from the useSession() on client side and use it to make API calls.
this is my api/auth/[...nextauth]/route.ts:
this is my authOptions.ts:
This is my user.interface.ts:
this is my next-auth.d.ts file:
I am using mongoDB, mongoose.
I can see my session-token in cookies upon successful login:
currently I see this for my session on client side, I want to be able to see a field for accessToken in my response below which allows me to extract this value and use it to make API calls from client side.
Please let me know if any more info required.
Beta Was this translation helpful? Give feedback.
All reactions