Refactoring

This commit is contained in:
charles-gauthereau
2024-11-11 10:26:40 +01:00
parent cfd8803b16
commit fd77c601b5
7 changed files with 8854 additions and 13 deletions
+25 -1
View File
@@ -52,6 +52,7 @@ export const {handlers, auth: baseAuth, signIn, signOut} = NextAuth({
name: profile.name,
email: profile.email,
image: profile.picture,
authMethod: "google",
}
},
})
@@ -66,8 +67,31 @@ export const {handlers, auth: baseAuth, signIn, signOut} = NextAuth({
callbacks: {
session({session, user, token}) {
// session.user.role = user.role
// session.user.authMethod = user.authMethod;
return session
}
},
async signIn({ account, user }) {
console.log(account)
// const authMethod = account.provider === 'credentials' ? 'credentials' : 'oauth';
user = await prisma.user.findFirst({
where: {
email: user.email,
}
})
if (!user) {
return true
}
console.log(user)
// Update the user in the database with the auth method
await prisma.user.update({
where: { id: user.id },
data: {
authMethod: account.provider
},
});
return true;
},
},
});