diff --git a/libs/auth/src/lib/pages/ForgotPasswordPage.tsx b/libs/auth/src/lib/pages/ForgotPasswordPage.tsx index 3b932d586..98552e2b8 100644 --- a/libs/auth/src/lib/pages/ForgotPasswordPage.tsx +++ b/libs/auth/src/lib/pages/ForgotPasswordPage.tsx @@ -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(null); + const [serverError, setServerError] = useState(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() { + {serverError && ( + setServerError(null)}> + {serverError} + + )} +
(null); const [loginTrigger] = useApiMutation(); const [meTrigger] = useApiMutation(); const [profileCheckTrigger] = useApiMutation<{ id: string }>(); @@ -101,8 +103,12 @@ export function LoginPage() { } navigate(loginRedirectPath); - } catch { - notify.error('Invalid email or password'); + } 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); } finally { setIsLoading(false); } @@ -120,6 +126,12 @@ export function LoginPage() { + {serverError && ( + setServerError(null)}> + {serverError} + + )} + (null); const [signupTrigger, { isLoading: loading }] = useApiMutation<{ token: string; refreshToken: string; @@ -123,8 +125,11 @@ export function SignupPage() { }, }); } - } 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); } }; @@ -144,6 +149,12 @@ export function SignupPage() { + {serverError && ( + setServerError(null)}> + {serverError} + + )} +