Enhance password update error handling and localization (#175)

* Enhance password update error handling and localization
This commit is contained in:
Giancarlo Buomprisco
2025-02-19 15:38:05 +07:00
committed by GitHub
parent 0808b91e0d
commit 031e0810a6
2 changed files with 19 additions and 6 deletions

View File

@@ -82,6 +82,7 @@
"minPasswordSpecialChars": "Password must contain at least one special character",
"uppercasePassword": "Password must contain at least one uppercase letter",
"insufficient_aal": "Please sign-in with your current multi-factor authentication to perform this action",
"otp_expired": "The email link has expired. Please try again."
"otp_expired": "The email link has expired. Please try again.",
"same_password": "The password cannot be the same as the current password"
}
}

View File

@@ -6,6 +6,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { CheckIcon, ExclamationTriangleIcon } from '@radix-ui/react-icons';
import { ArrowRightIcon } from 'lucide-react';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import type { z } from 'zod';
import { useUpdateUser } from '@kit/supabase/hooks/use-update-user-mutation';
@@ -37,7 +38,9 @@ export function UpdatePasswordForm(params: { redirectTo: string }) {
});
if (updateUser.error) {
return <ErrorState onRetry={() => updateUser.reset()} />;
const error = updateUser.error as unknown as { code: string };
return <ErrorState error={error} onRetry={() => updateUser.reset()} />;
}
if (updateUser.data && !updateUser.isPending) {
@@ -139,7 +142,18 @@ function SuccessState(props: { redirectTo: string }) {
);
}
function ErrorState(props: { onRetry: () => void }) {
function ErrorState(props: {
onRetry: () => void;
error: {
code: string;
};
}) {
const { t } = useTranslation('auth');
const errorMessage = t(`errors.${props.error.code}`, {
defaultValue: t('errors.resetPasswordError'),
});
return (
<div className={'flex flex-col space-y-4'}>
<Alert variant={'destructive'}>
@@ -149,9 +163,7 @@ function ErrorState(props: { onRetry: () => void }) {
<Trans i18nKey={'common:genericError'} />
</AlertTitle>
<AlertDescription>
<Trans i18nKey={'auth:resetPasswordError'} />
</AlertDescription>
<AlertDescription>{errorMessage}</AlertDescription>
</Alert>
<Button onClick={props.onRetry} variant={'outline'}>