Skip to content

Commit

Permalink
feat: add disabled property for user (documenso#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
catalinpit authored Dec 17, 2024
1 parent c960a48 commit c161553
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/web/src/components/forms/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ERROR_MESSAGES: Partial<Record<keyof typeof ErrorCode, string>> = {
[ErrorCode.INCORRECT_TWO_FACTOR_BACKUP_CODE]: 'The backup code provided is incorrect',
[ErrorCode.UNVERIFIED_EMAIL]:
'This account has not been verified. Please verify your account before signing in.',
[ErrorCode.ACCOUNT_DISABLED]: 'This account has been disabled. Please contact support.',
};

const TwoFactorEnabledErrorCode = ErrorCode.TWO_FACTOR_MISSING_CREDENTIALS;
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/next-auth/auth-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export const NEXT_AUTH_OPTIONS: AuthOptions = {
throw new Error(ErrorCode.UNVERIFIED_EMAIL);
}

if (user.disabled) {
throw new Error(ErrorCode.ACCOUNT_DISABLED);
}

return {
id: Number(user.id),
email: user.email,
Expand Down
1 change: 1 addition & 0 deletions packages/lib/next-auth/error-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export const ErrorCode = {
MISSING_ENCRYPTION_KEY: 'MISSING_ENCRYPTION_KEY',
MISSING_BACKUP_CODE: 'MISSING_BACKUP_CODE',
UNVERIFIED_EMAIL: 'UNVERIFIED_EMAIL',
ACCOUNT_DISABLED: 'ACCOUNT_DISABLED',
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "disabled" BOOLEAN NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions packages/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ model User {
roles Role[] @default([USER])
identityProvider IdentityProvider @default(DOCUMENSO)
avatarImageId String?
disabled Boolean @default(false)
accounts Account[]
sessions Session[]
Expand Down

0 comments on commit c161553

Please sign in to comment.