The Open Source DocuSign Alternative.
TypeScript digital-signaturedocument-signingdocusign-alternativee-signatureesignesignaturenext-authnextjsopen-sourcepades-standardpdfpdf-signpdf-signaturepostgresqlprismaself-hostedsigningtypescript
fix: authentication
nafees nazik7a74f3c77ef2
diff --git a/packages/lib/next-auth/auth-options.ts b/packages/lib/next-auth/auth-options.tsindex a4bf1e631..8166cda36 100644--- a/packages/lib/next-auth/auth-options.ts+++ b/packages/lib/next-auth/auth-options.ts@@ -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 {diff --git a/packages/lib/next-auth/error-codes.ts b/packages/lib/next-auth/error-codes.tsnew file mode 100644index 000000000..f0a7caada--- /dev/null+++ b/packages/lib/next-auth/error-codes.ts@@ -0,0 +1,5 @@+export const ErrorCodes = {+ IncorrectEmailPassword: 'incorrect-email-password',+ UserMissingPassword: 'missing-password',+ CredentialsNotFound: 'credentials-not-found',+} as const;