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 <55134778+sean-brydon@users.noreply.github.com>

* Linting

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
pull/4138/head^2
Hariom Balhara 2022-09-05 23:09:16 +05:30 committed by GitHub
parent ebd4ce0340
commit 10815c9541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 19 deletions

View File

@ -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();
}