How does NextAuth save user info to the database with the prisma adapter?

Is it possible to see the function that nextauth calls to save user info to the database? Is there a way to console.log what the Provider returns after signing in? I'd like to add one more field to the User schema like their Facebook Public Profile ID after signing in when using FacebookProvider but I don't know where to start.
2 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
esponges
esponges3y ago
in authOptions you can add a callBack element for signIn where you can store the information you've gotten from the auth. I tested with something like this:
export const authOptions: NextAuthOptions = {
// Include user.id on session
callbacks: {
session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
return session;
},
// register user in logbook when they log in
async signIn({ user, account, profile, email, credentials }) {
try {
await prisma.logbook.create({
data: {
name: user.name,
email: user.email,
lastLogin: new Date(),
},
});
} catch (e) {
console.log("error login logBook data :", e);
}
return true;
},
},
export const authOptions: NextAuthOptions = {
// Include user.id on session
callbacks: {
session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
return session;
},
// register user in logbook when they log in
async signIn({ user, account, profile, email, credentials }) {
try {
await prisma.logbook.create({
data: {
name: user.name,
email: user.email,
lastLogin: new Date(),
},
});
} catch (e) {
console.log("error login logBook data :", e);
}
return true;
},
},
Want results from more Discord servers?
Add your server