feat(auth): add server error alerts to authentication pages commit

This commit is contained in:
mengstabketemaw
2026-06-29 10:20:26 +03:00
parent 346c3585c1
commit 3493fbbae7
3 changed files with 45 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import { useState } from 'react';
import {
Alert,
Anchor,
Button,
Center,
@@ -35,6 +36,7 @@ export function ForgotPasswordPage() {
const { appName } = useAuthConfig();
const [forgotTrigger, { isLoading }] = useApiMutation();
const [sentTo, setSentTo] = useState<string | null>(null);
const [serverError, setServerError] = useState<string | null>(null);
const {
register,
@@ -56,8 +58,11 @@ export function ForgotPasswordPage() {
const onSubmit = async (values: FormValues) => {
try {
await sendResetLink(values.email);
} catch (err) {
const msg = err instanceof Error ? err.message : 'Something went wrong';
} catch (err: unknown) {
const msg =
(err as { data?: { message?: string } })?.data?.message ??
(err instanceof Error ? err.message : 'Something went wrong');
setServerError(msg);
notify.error(msg);
}
};
@@ -67,8 +72,11 @@ export function ForgotPasswordPage() {
try {
await sendResetLink(sentTo);
notify.success('Reset link sent again');
} catch (err) {
const msg = err instanceof Error ? err.message : 'Something went wrong';
} catch (err: unknown) {
const msg =
(err as { data?: { message?: string } })?.data?.message ??
(err instanceof Error ? err.message : 'Something went wrong');
setServerError(msg);
notify.error(msg);
}
};
@@ -160,6 +168,12 @@ export function ForgotPasswordPage() {
</Text>
</div>
{serverError && (
<Alert variant="light" color="red" withCloseButton onClose={() => setServerError(null)}>
{serverError}
</Alert>
)}
<form onSubmit={handleSubmit(onSubmit)}>
<Stack gap="md">
<TextInput