create-t3-app next auth question

In the default auth settings for t3, I noticed id: token.sub in the callbacks making the id available on the user object. Is this sub something I can use as my unique user/account id in my db? What is sub?
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, token }) => ({
...session,
user: {
...session.user,
id: token.sub,
},
}),
},
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, token }) => ({
...session,
user: {
...session.user,
id: token.sub,
},
}),
},
Solution:
GitHub
JWT sub property · nextauthjs next-auth · Discussion #6695
Question 💬 I am currently working on Nextjs project and using nextAuth for authentication . right now whenever any user completes sign in then the JWT generated has sub property which always contai...
Jump to solution
7 Replies
Solution
Vincent Udén
Vincent Udén4mo ago
GitHub
JWT sub property · nextauthjs next-auth · Discussion #6695
Question 💬 I am currently working on Nextjs project and using nextAuth for authentication . right now whenever any user completes sign in then the JWT generated has sub property which always contai...
Vengeance
Vengeance4mo ago
So if someone signs in with apple, google, or custom credentials, they will all be given that unique id in sub that won't be changed unless I change it?
Vincent Udén
Vincent Udén4mo ago
Im not sure what you are asking. A sign in using apple would be a new user even if a google account exists with the same email linked to it. If that is what you are asking
Vengeance
Vengeance4mo ago
yes, thank you 🙏
Vincent Udén
Vincent Udén4mo ago
NextAuth has no way of know if a person in real life has multiple accounts on different services. Im not even sure how it would know that. That's why they are all distinct
Vengeance
Vengeance4mo ago
i just wanted to make sure the sub would be unique and never change (other than by me) so that it would be ok to use that as the unique identifier for my users
Vincent Udén
Vincent Udén4mo ago
Allright, please mark the question as solved by the way
Want results from more Discord servers?
Add your server
More Posts