Get user from token as required for magic login to work (#4163)
* Get user from token as required for magic login to work * Update apps/web/pages/api/auth/[...nextauth].tsx Co-authored-by: sean-brydon <[email protected]> * Linting Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 file changed
+14
-19
@@ -215,29 +215,24 @@ export default NextAuth({
|
||||
callbacks: {
|
||||
async jwt({ token, user, account }) {
|
||||
const autoMergeIdentities = async () => {
|
||||
if (!hostedCal) {
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
where: { email: token.email! },
|
||||
});
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
where: { email: token.email! },
|
||||
});
|
||||
|
||||
if (!existingUser) {
|
||||
return token;
|
||||
}
|
||||
|
||||
return {
|
||||
id: existingUser.id,
|
||||
username: existingUser.username,
|
||||
name: existingUser.name,
|
||||
email: existingUser.email,
|
||||
role: existingUser.role,
|
||||
impersonatedByUID: token?.impersonatedByUID as number,
|
||||
};
|
||||
if (!existingUser) {
|
||||
return token;
|
||||
}
|
||||
|
||||
return token;
|
||||
return {
|
||||
id: existingUser.id,
|
||||
username: existingUser.username,
|
||||
name: existingUser.name,
|
||||
email: existingUser.email,
|
||||
role: existingUser.role,
|
||||
impersonatedByUID: token?.impersonatedByUID as number,
|
||||
};
|
||||
};
|
||||
|
||||
if (!user) {
|
||||
return await autoMergeIdentities();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user