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:
authored and GitHub committed 2022-09-05 11:39:16 -06:00
1 parent ebd4ce0340
commit 10815c9541
1 file changed
+14 -19
+14 -19
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();
}