From 5cba252627d4049b0bf4dd5a069361cb2d402ea0 Mon Sep 17 00:00:00 2001 From: Mythie Date: Wed, 30 Aug 2023 14:01:30 +1000 Subject: [PATCH] fix: minor tidying --- apps/web/src/components/forms/password.tsx | 2 +- packages/lib/server-only/user/update-password.ts | 2 +- packages/trpc/server/profile-router/router.ts | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/forms/password.tsx b/apps/web/src/components/forms/password.tsx index de0b9f1e0..a9bd81af4 100644 --- a/apps/web/src/components/forms/password.tsx +++ b/apps/web/src/components/forms/password.tsx @@ -80,7 +80,7 @@ export const PasswordForm = ({ className }: PasswordFormProps) => { title: 'An unknown error occurred', variant: 'destructive', description: - 'We encountered an unknown error while attempting to sign you In. Please try again later.', + 'We encountered an unknown error while attempting to update your password. Please try again later.', }); } } diff --git a/packages/lib/server-only/user/update-password.ts b/packages/lib/server-only/user/update-password.ts index 521aecd22..4133bc342 100644 --- a/packages/lib/server-only/user/update-password.ts +++ b/packages/lib/server-only/user/update-password.ts @@ -23,7 +23,7 @@ export const updatePassword = async ({ userId, password }: UpdatePasswordOptions const isSamePassword = await compare(password, user.password as string); if (isSamePassword) { - throw new Error('You cannot use the same password as your current password.'); + throw new Error('Your new password cannot be the same as your old password.'); } const updatedUser = await prisma.user.update({ diff --git a/packages/trpc/server/profile-router/router.ts b/packages/trpc/server/profile-router/router.ts index 76e50473d..1ca8a0cf2 100644 --- a/packages/trpc/server/profile-router/router.ts +++ b/packages/trpc/server/profile-router/router.ts @@ -40,13 +40,16 @@ export const profileRouter = router({ password, }); } catch (err) { - const errorMessage = (err as { message?: string }).message; + let message = + 'We were unable to update your profile. Please review the information you provided and try again.'; + + if (err instanceof Error) { + message = err.message; + } throw new TRPCError({ code: 'BAD_REQUEST', - message: errorMessage - ? errorMessage - : 'We were unable to update your profile. Please review the information you provided and try again.', + message, }); } }),