How do I get a userId when using Google auth? #788
Replies: 7 comments 4 replies
-
Update: I found a user id from
|
Beta Was this translation helpful? Give feedback.
-
I finally figured it out. There's a very short sentence in the JWT callback section of the docs that explains that the jwt callback is called with all the params only during sign in.
|
Beta Was this translation helpful? Give feedback.
-
Buena viejo, me has salvado. 👍 |
Beta Was this translation helpful? Give feedback.
-
the next auth configuration below gives access to the id in your session object as well. callbacks: {
session({ session, token }) {
if (session.user) {
session.user.id = token.sub as string;
}
return session;
},
},
secret: [YOUR_AUTH_SECRET],
session: {
strategy: "jwt",
}, |
Beta Was this translation helpful? Give feedback.
-
This works perfectly for me, as I am using MongoDB adapter, google provider, and credentials provider
|
Beta Was this translation helpful? Give feedback.
-
Please explain the how i can override id when using google auth i want to use backend userid not google id import NextAuth from "next-auth"; const handler = NextAuth({
],
}, export { handler as GET, handler as POST }; |
Beta Was this translation helpful? Give feedback.
-
For me the issue was getting a consistent, unique user id from a provider. The user.id or token.id field could change between logins. Example:
|
Beta Was this translation helpful? Give feedback.
-
Your question
How do I get a userId? Is it the JWT? Is it the
accessToken
? If so, how do I get that?What are you trying to do
I need to identify my users for both my API routes in Hasura and Log Rocket (along with everything else). I searched through the docs, but it's not clear to me what I would use as the unique ID for users. I used the Google Auth Provider, signed in, and found this as the session object with
useSession
It seems I'm missing the
accessToken
mentioned in the docs here. I also referred to the callbacks documentation , but I can't seem to find an id anywhere, just anexp
andiat
. What do I need to do?Here is my
[...nextAuth].ts
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
Beta Was this translation helpful? Give feedback.
All reactions