You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use NextAuth for authentication. The idea is to let users login with socials of their choice e.g. FB, Twitter, Google
Upon logging in, I use the signIn callback to check for their profile details (if present), and also whether they are banned. I store their email received from the third-party sign in providers, and on-top of that, additional info e.g. last sign in, account statistics.
However, I want these information e.g. lastSignIn, postCount to also be visible in the session.
I know we can use the session callback to add values to the session but I am not sure how to get the information I've collected in the signIn callback and place it in the session, if that makes sense. I want to only check for these details once during the signIn callback.
Is my approach above correct? Or what is the correct way to login with third-party sites (Google, FB), and then verify that a user exists in system, and also get user-specific variables and place them in the session?
How to reproduce ☕️
What I have so far:
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
// ...add more providers here
],
secret: process.env.AUTH_SECRET,
callbacks: {
async signIn({ user }) {
// check database for user credentials e.g. lastSignIn, postCount
return true
},
async jwt({ token, account }) {
// Persist the OAuth access_token to the token right after signin
if (account) {
token.accessToken = account.access_token
}
return token
},
async session({ session, token, user }) {
// Send properties to the client, like an access_token from a provider.
session.accessToken = token.accessToken
return session
}
}
questionAsk how to do something or how something works
1 participant
Converted from issue
This discussion was converted from issue #3433 on December 13, 2021 10:56.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question 💬
Hello,
I am trying to use NextAuth for authentication. The idea is to let users login with socials of their choice e.g. FB, Twitter, Google
Upon logging in, I use the signIn callback to check for their profile details (if present), and also whether they are banned. I store their email received from the third-party sign in providers, and on-top of that, additional info e.g. last sign in, account statistics.
However, I want these information e.g. lastSignIn, postCount to also be visible in the session.
I know we can use the session callback to add values to the session but I am not sure how to get the information I've collected in the signIn callback and place it in the session, if that makes sense. I want to only check for these details once during the signIn callback.
Is my approach above correct? Or what is the correct way to login with third-party sites (Google, FB), and then verify that a user exists in system, and also get user-specific variables and place them in the session?
How to reproduce ☕️
What I have so far:
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
// ...add more providers here
],
secret: process.env.AUTH_SECRET,
callbacks: {
async signIn({ user }) {
// check database for user credentials e.g. lastSignIn, postCount
return true
},
async jwt({ token, account }) {
// Persist the OAuth access_token to the token right after signin
if (account) {
token.accessToken = account.access_token
}
return token
},
async session({ session, token, user }) {
// Send properties to the client, like an access_token from a provider.
session.accessToken = token.accessToken
return session
}
}
Contributing 🙌🏽
No, I am afraid I cannot help regarding this
Beta Was this translation helpful? Give feedback.
All reactions