From 311c8da8fc8ad5ded8f8ed11146a517e740f07b5 Mon Sep 17 00:00:00 2001 From: Catalin Pit <25515812+catalinpit@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:24:37 +0200 Subject: [PATCH] chore: encrypt and decrypt email addr --- .../src/app/(unauthenticated)/unverified-account/page.tsx | 6 ++---- packages/trpc/server/profile-router/router.ts | 5 ++++- packages/trpc/server/profile-router/schema.ts | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/web/src/app/(unauthenticated)/unverified-account/page.tsx b/apps/web/src/app/(unauthenticated)/unverified-account/page.tsx index 456971a9f..5199249e0 100644 --- a/apps/web/src/app/(unauthenticated)/unverified-account/page.tsx +++ b/apps/web/src/app/(unauthenticated)/unverified-account/page.tsx @@ -18,7 +18,7 @@ export default function UnverifiedAccount() { const searchParams = useSearchParams(); const { toast } = useToast(); - const token = searchParams?.get('t') ?? ''; + const encryptedEmail = searchParams?.get('t') ?? ''; // TODO: choose a better name instead of t const { mutateAsync: sendConfirmationEmail } = trpc.profile.sendConfirmationEmail.useMutation(); @@ -26,9 +26,7 @@ export default function UnverifiedAccount() { try { setIsButtonDisabled(true); - // TODO: decrypt email and send it - - await sendConfirmationEmail({ email: token ?? '' }); + await sendConfirmationEmail({ email: encryptedEmail }); toast({ title: 'Success', diff --git a/packages/trpc/server/profile-router/router.ts b/packages/trpc/server/profile-router/router.ts index 09ee0351f..510e2a6fd 100644 --- a/packages/trpc/server/profile-router/router.ts +++ b/packages/trpc/server/profile-router/router.ts @@ -1,5 +1,6 @@ import { TRPCError } from '@trpc/server'; +import { decryptSecondaryData } from '@documenso/lib/server-only/crypto/decrypt'; import { forgotPassword } from '@documenso/lib/server-only/user/forgot-password'; import { getUserByEmail } from '@documenso/lib/server-only/user/get-user-by-email'; import { getUserById } from '@documenso/lib/server-only/user/get-user-by-id'; @@ -136,7 +137,9 @@ export const profileRouter = router({ try { const { email } = input; - return await sendConfirmationToken({ email }); + const decryptedEmail = decryptSecondaryData(email); + + return await sendConfirmationToken({ email: decryptedEmail ?? '' }); // TODO: fix this tomorrow } catch (err) { let message = 'We were unable to send a confirmation email. Please try again.'; diff --git a/packages/trpc/server/profile-router/schema.ts b/packages/trpc/server/profile-router/schema.ts index 671756e94..5aa9844ca 100644 --- a/packages/trpc/server/profile-router/schema.ts +++ b/packages/trpc/server/profile-router/schema.ts @@ -30,9 +30,9 @@ export const ZResetPasswordFormSchema = z.object({ password: z.string().min(6), token: z.string().min(1), }); - +// TODO: revisit this export const ZConfirmEmailMutationSchema = z.object({ - email: z.string().email().min(1), + email: z.string().min(1), }); export type TRetrieveUserByIdQuerySchema = z.infer;