mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
fix: authentication
This commit is contained in:
@ -7,6 +7,7 @@ import GoogleProvider, { GoogleProfile } from 'next-auth/providers/google';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { getUserByEmail } from '../server-only/user/get-user-by-email';
|
||||
import { ErrorCodes } from './error-codes';
|
||||
|
||||
export const NEXT_AUTH_OPTIONS: AuthOptions = {
|
||||
adapter: PrismaAdapter(prisma),
|
||||
@ -23,21 +24,23 @@ export const NEXT_AUTH_OPTIONS: AuthOptions = {
|
||||
},
|
||||
authorize: async (credentials, _req) => {
|
||||
if (!credentials) {
|
||||
return null;
|
||||
throw new Error(ErrorCodes.CredentialsNotFound);
|
||||
}
|
||||
|
||||
const { email, password } = credentials;
|
||||
|
||||
const user = await getUserByEmail({ email }).catch(() => null);
|
||||
const user = await getUserByEmail({ email }).catch(() => {
|
||||
throw new Error(ErrorCodes.IncorrectEmailPassword);
|
||||
});
|
||||
|
||||
if (!user || !user.password) {
|
||||
return null;
|
||||
if (!user.password) {
|
||||
throw new Error(ErrorCodes.UserMissingPassword);
|
||||
}
|
||||
|
||||
const isPasswordsSame = compare(password, user.password);
|
||||
const isPasswordsSame = await compare(password, user.password);
|
||||
|
||||
if (!isPasswordsSame) {
|
||||
return null;
|
||||
throw new Error(ErrorCodes.IncorrectEmailPassword);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
5
packages/lib/next-auth/error-codes.ts
Normal file
5
packages/lib/next-auth/error-codes.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export const ErrorCodes = {
|
||||
IncorrectEmailPassword: 'incorrect-email-password',
|
||||
UserMissingPassword: 'missing-password',
|
||||
CredentialsNotFound: 'credentials-not-found',
|
||||
} as const;
|
||||
Reference in New Issue
Block a user