Enhance password update error handling and localization (#175)
* Enhance password update error handling and localization
This commit is contained in:
committed by
GitHub
parent
0808b91e0d
commit
031e0810a6
@@ -82,6 +82,7 @@
|
|||||||
"minPasswordSpecialChars": "Password must contain at least one special character",
|
"minPasswordSpecialChars": "Password must contain at least one special character",
|
||||||
"uppercasePassword": "Password must contain at least one uppercase letter",
|
"uppercasePassword": "Password must contain at least one uppercase letter",
|
||||||
"insufficient_aal": "Please sign-in with your current multi-factor authentication to perform this action",
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
|||||||
import { CheckIcon, ExclamationTriangleIcon } from '@radix-ui/react-icons';
|
import { CheckIcon, ExclamationTriangleIcon } from '@radix-ui/react-icons';
|
||||||
import { ArrowRightIcon } from 'lucide-react';
|
import { ArrowRightIcon } from 'lucide-react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import type { z } from 'zod';
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { useUpdateUser } from '@kit/supabase/hooks/use-update-user-mutation';
|
import { useUpdateUser } from '@kit/supabase/hooks/use-update-user-mutation';
|
||||||
@@ -37,7 +38,9 @@ export function UpdatePasswordForm(params: { redirectTo: string }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (updateUser.error) {
|
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) {
|
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 (
|
return (
|
||||||
<div className={'flex flex-col space-y-4'}>
|
<div className={'flex flex-col space-y-4'}>
|
||||||
<Alert variant={'destructive'}>
|
<Alert variant={'destructive'}>
|
||||||
@@ -149,9 +163,7 @@ function ErrorState(props: { onRetry: () => void }) {
|
|||||||
<Trans i18nKey={'common:genericError'} />
|
<Trans i18nKey={'common:genericError'} />
|
||||||
</AlertTitle>
|
</AlertTitle>
|
||||||
|
|
||||||
<AlertDescription>
|
<AlertDescription>{errorMessage}</AlertDescription>
|
||||||
<Trans i18nKey={'auth:resetPasswordError'} />
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
<Button onClick={props.onRetry} variant={'outline'}>
|
<Button onClick={props.onRetry} variant={'outline'}>
|
||||||
|
|||||||
Reference in New Issue
Block a user