mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
fix: auto verify google sso emails (#856)
This commit is contained in:
@ -9,6 +9,7 @@ import type { GoogleProfile } from 'next-auth/providers/google';
|
|||||||
import GoogleProvider from 'next-auth/providers/google';
|
import GoogleProvider from 'next-auth/providers/google';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import { IdentityProvider } from '@documenso/prisma/client';
|
||||||
|
|
||||||
import { isTwoFactorAuthenticationEnabled } from '../server-only/2fa/is-2fa-availble';
|
import { isTwoFactorAuthenticationEnabled } from '../server-only/2fa/is-2fa-availble';
|
||||||
import { validateTwoFactorAuthentication } from '../server-only/2fa/validate-2fa';
|
import { validateTwoFactorAuthentication } from '../server-only/2fa/validate-2fa';
|
||||||
@ -93,7 +94,7 @@ export const NEXT_AUTH_OPTIONS: AuthOptions = {
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
callbacks: {
|
callbacks: {
|
||||||
async jwt({ token, user }) {
|
async jwt({ token, user, trigger, account }) {
|
||||||
const merged = {
|
const merged = {
|
||||||
...token,
|
...token,
|
||||||
...user,
|
...user,
|
||||||
@ -138,6 +139,22 @@ export const NEXT_AUTH_OPTIONS: AuthOptions = {
|
|||||||
merged.emailVerified = user.emailVerified?.toISOString() ?? null;
|
merged.emailVerified = user.emailVerified?.toISOString() ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((trigger === 'signIn' || trigger === 'signUp') && account?.provider === 'google') {
|
||||||
|
merged.emailVerified = user?.emailVerified
|
||||||
|
? new Date(user.emailVerified).toISOString()
|
||||||
|
: new Date().toISOString();
|
||||||
|
|
||||||
|
await prisma.user.update({
|
||||||
|
where: {
|
||||||
|
id: Number(merged.id),
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
emailVerified: merged.emailVerified,
|
||||||
|
identityProvider: IdentityProvider.GOOGLE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: merged.id,
|
id: merged.id,
|
||||||
name: merged.name,
|
name: merged.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user