The Open Source DocuSign Alternative.
TypeScript digital-signaturedocument-signingdocusign-alternativee-signatureesignesignaturenext-authnextjsopen-sourcepades-standardpdfpdf-signpdf-signaturepostgresqlprismaself-hostedsigningtypescript
feat: request usee to disable 2fa before deleting account
Ephraim Atta-Duncanf98567ea8785
diff --git a/apps/web/src/components/forms/profile.tsx b/apps/web/src/components/forms/profile.tsxindex 23861c9fc..8a7e2ff3f 100644--- a/apps/web/src/components/forms/profile.tsx+++ b/apps/web/src/components/forms/profile.tsx@@ -7,7 +7,6 @@ import { signOut } from 'next-auth/react';import { useForm } from 'react-hook-form';import { z } from 'zod';-import { validateTwoFactorAuthentication } from '@documenso/lib/server-only/2fa/validate-2fa';import type { User } from '@documenso/prisma/client';import { TRPCClientError } from '@documenso/trpc/client';import { trpc } from '@documenso/trpc/react';@@ -67,13 +66,6 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => {resolver: zodResolver(ZProfileFormSchema),});- const deleteAccountTwoFactorTokenForm = useForm<TTwoFactorAuthTokenSchema>({- defaultValues: {- token: '',- },- resolver: zodResolver(ZTwoFactorAuthTokenSchema),- });-const isSubmitting = form.formState.isSubmitting;const hasTwoFactorAuthentication = user.twoFactorEnabled;@@ -113,38 +105,17 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => {}};- const deleteAccoutAndSignOut = async () => {- await deleteAccount();-- toast({- title: 'Account deleted',- description: 'Your account has been deleted successfully.',- duration: 5000,- });-- return await signOut({ callbackUrl: '/' });- };-- const onDeleteAccount = async (hasTwoFactorAuthentication: boolean) => {+ const onDeleteAccount = async () => {try {- if (!hasTwoFactorAuthentication) {- return await deleteAccoutAndSignOut();- }+ await deleteAccount();- const { token } = deleteAccountTwoFactorTokenForm.getValues();-- if (!token) {- throw new Error('Please enter your Two Factor Authentication token.');- }-- await validateTwoFactorAuthentication({- totpCode: token,- user,- }).catch(() => {- throw new Error('We were unable to validate your Two Factor Authentication token.');+ toast({+ title: 'Account deleted',+ description: 'Your account has been deleted successfully.',+ duration: 5000,});- await deleteAccoutAndSignOut();+ return await signOut({ callbackUrl: '/' });} catch (err) {if (err instanceof TRPCClientError && err.data?.code === 'BAD_REQUEST') {toast({@@ -225,66 +196,47 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => {irreversible and will cancel your subscription, so proceed with caution.</CardContent><CardFooter className="justify-end pb-4 pr-4">- <Form {...deleteAccountTwoFactorTokenForm}>- <form- onSubmit={deleteAccountTwoFactorTokenForm.handleSubmit(() => {- console.log('delete account');- })}- >- <Dialog>- <DialogTrigger asChild>- <Button variant="destructive">Delete Account</Button>- </DialogTrigger>- <DialogContent>- <DialogHeader>- <DialogTitle>Delete Account</DialogTitle>- <DialogDescription>- Documenso will delete{' '}- <span className="font-semibold">all of your documents</span>, along with all- of your completed documents, signatures, and all other resources belonging- to your Account.- </DialogDescription>- </DialogHeader>-- <Alert variant="destructive">- <AlertDescription className="selection:bg-red-100">- This action is not reversible. Please be certain.- </AlertDescription>- </Alert>-- {hasTwoFactorAuthentication && (- <div className="flex flex-col gap-y-4">- <FormField- name="token"- control={deleteAccountTwoFactorTokenForm.control}- render={({ field }) => (- <FormItem>- <FormLabel className="text-muted-foreground">- Two Factor Authentication Token- </FormLabel>- <FormControl>- <Input {...field} value={field.value ?? ''} />- </FormControl>- <FormMessage />- </FormItem>- )}- />- </div>- )}-- <DialogFooter>- <Button- onClick={async () => onDeleteAccount(hasTwoFactorAuthentication)}- loading={isDeletingAccount}- variant="destructive"- >- {isDeletingAccount ? 'Deleting account...' : 'Delete Account'}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>- </form>- </Form>+ <Dialog>+ <DialogTrigger asChild>+ <Button variant="destructive">Delete Account</Button>+ </DialogTrigger>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>Delete Account</DialogTitle>+ <DialogDescription>+ Documenso will delete{' '}+ <span className="font-semibold">all of your documents</span>, along with all of+ your completed documents, signatures, and all other resources belonging to your+ Account.+ </DialogDescription>+ </DialogHeader>++ <Alert variant="destructive">+ <AlertDescription className="selection:bg-red-100">+ This action is not reversible. Please be certain.+ </AlertDescription>+ </Alert>++ {hasTwoFactorAuthentication && (+ <Alert variant="destructive">+ <AlertDescription className="selection:bg-red-100">+ Disable Two Factor Authentication before deleting your account.+ </AlertDescription>+ </Alert>+ )}++ <DialogFooter>+ <Button+ onClick={onDeleteAccount}+ loading={isDeletingAccount}+ variant="destructive"+ disabled={hasTwoFactorAuthentication}+ >+ {isDeletingAccount ? 'Deleting account...' : 'Delete Account'}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog></CardFooter></Card></div>diff --git a/packages/lib/server-only/2fa/verify-2fa-token.ts b/packages/lib/server-only/2fa/verify-2fa-token.tsindex 3c410bd58..0e8ec6afc 100644--- a/packages/lib/server-only/2fa/verify-2fa-token.ts+++ b/packages/lib/server-only/2fa/verify-2fa-token.ts@@ -17,7 +17,6 @@ export const verifyTwoFactorAuthenticationToken = async ({user,totpCode,}: VerifyTwoFactorAuthenticationTokenOptions) => {- // TODO: This is undefined and I can't figure out why.const key = DOCUMENSO_ENCRYPTION_KEY;if (!user.twoFactorSecret) {