mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-07 23:35:43 +00:00
feat(auth): add server error alerts to authentication pages commit
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
Anchor,
|
Anchor,
|
||||||
Button,
|
Button,
|
||||||
Center,
|
Center,
|
||||||
@@ -35,6 +36,7 @@ export function ForgotPasswordPage() {
|
|||||||
const { appName } = useAuthConfig();
|
const { appName } = useAuthConfig();
|
||||||
const [forgotTrigger, { isLoading }] = useApiMutation();
|
const [forgotTrigger, { isLoading }] = useApiMutation();
|
||||||
const [sentTo, setSentTo] = useState<string | null>(null);
|
const [sentTo, setSentTo] = useState<string | null>(null);
|
||||||
|
const [serverError, setServerError] = useState<string | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@@ -56,8 +58,11 @@ export function ForgotPasswordPage() {
|
|||||||
const onSubmit = async (values: FormValues) => {
|
const onSubmit = async (values: FormValues) => {
|
||||||
try {
|
try {
|
||||||
await sendResetLink(values.email);
|
await sendResetLink(values.email);
|
||||||
} catch (err) {
|
} catch (err: unknown) {
|
||||||
const msg = err instanceof Error ? err.message : 'Something went wrong';
|
const msg =
|
||||||
|
(err as { data?: { message?: string } })?.data?.message ??
|
||||||
|
(err instanceof Error ? err.message : 'Something went wrong');
|
||||||
|
setServerError(msg);
|
||||||
notify.error(msg);
|
notify.error(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -67,8 +72,11 @@ export function ForgotPasswordPage() {
|
|||||||
try {
|
try {
|
||||||
await sendResetLink(sentTo);
|
await sendResetLink(sentTo);
|
||||||
notify.success('Reset link sent again');
|
notify.success('Reset link sent again');
|
||||||
} catch (err) {
|
} catch (err: unknown) {
|
||||||
const msg = err instanceof Error ? err.message : 'Something went wrong';
|
const msg =
|
||||||
|
(err as { data?: { message?: string } })?.data?.message ??
|
||||||
|
(err instanceof Error ? err.message : 'Something went wrong');
|
||||||
|
setServerError(msg);
|
||||||
notify.error(msg);
|
notify.error(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -160,6 +168,12 @@ export function ForgotPasswordPage() {
|
|||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{serverError && (
|
||||||
|
<Alert variant="light" color="red" withCloseButton onClose={() => setServerError(null)}>
|
||||||
|
{serverError}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
Anchor,
|
Anchor,
|
||||||
Button,
|
Button,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@@ -44,6 +45,7 @@ export function LoginPage() {
|
|||||||
useAuthConfig();
|
useAuthConfig();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [rememberMe, setRememberMe] = useState(true);
|
const [rememberMe, setRememberMe] = useState(true);
|
||||||
|
const [serverError, setServerError] = useState<string | null>(null);
|
||||||
const [loginTrigger] = useApiMutation<LoginPayload>();
|
const [loginTrigger] = useApiMutation<LoginPayload>();
|
||||||
const [meTrigger] = useApiMutation<AuthUser>();
|
const [meTrigger] = useApiMutation<AuthUser>();
|
||||||
const [profileCheckTrigger] = useApiMutation<{ id: string }>();
|
const [profileCheckTrigger] = useApiMutation<{ id: string }>();
|
||||||
@@ -101,8 +103,12 @@ export function LoginPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
navigate(loginRedirectPath);
|
navigate(loginRedirectPath);
|
||||||
} catch {
|
} catch (err: unknown) {
|
||||||
notify.error('Invalid email or password');
|
const msg =
|
||||||
|
(err as { data?: { message?: string } })?.data?.message ??
|
||||||
|
(err instanceof Error ? err.message : 'Something went wrong');
|
||||||
|
setServerError(msg);
|
||||||
|
notify.error(msg);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -120,6 +126,12 @@ export function LoginPage() {
|
|||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{serverError && (
|
||||||
|
<Alert variant="light" color="red" withCloseButton onClose={() => setServerError(null)}>
|
||||||
|
{serverError}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
Anchor,
|
Anchor,
|
||||||
Button,
|
Button,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@@ -67,6 +68,7 @@ export function SignupPage() {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { appName, loginRedirectPath } = useAuthConfig();
|
const { appName, loginRedirectPath } = useAuthConfig();
|
||||||
const [agreed, setAgreed] = useState(false);
|
const [agreed, setAgreed] = useState(false);
|
||||||
|
const [serverError, setServerError] = useState<string | null>(null);
|
||||||
const [signupTrigger, { isLoading: loading }] = useApiMutation<{
|
const [signupTrigger, { isLoading: loading }] = useApiMutation<{
|
||||||
token: string;
|
token: string;
|
||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
@@ -123,8 +125,11 @@ export function SignupPage() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err: unknown) {
|
||||||
const msg = err instanceof Error ? err.message : 'Something went wrong';
|
const msg =
|
||||||
|
(err as { data?: { message?: string } })?.data?.message ??
|
||||||
|
(err instanceof Error ? err.message : 'Something went wrong');
|
||||||
|
setServerError(msg);
|
||||||
notify.error(msg);
|
notify.error(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -144,6 +149,12 @@ export function SignupPage() {
|
|||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{serverError && (
|
||||||
|
<Alert variant="light" color="red" withCloseButton onClose={() => setServerError(null)}>
|
||||||
|
{serverError}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
<SimpleGrid cols={{ base: 1, xs: 2 }} spacing="md">
|
<SimpleGrid cols={{ base: 1, xs: 2 }} spacing="md">
|
||||||
|
|||||||
Reference in New Issue
Block a user