diff --git a/apps/infoalloggi/src/forms/FormLogin.tsx b/apps/infoalloggi/src/forms/FormLogin.tsx index a01174c..1273155 100644 --- a/apps/infoalloggi/src/forms/FormLogin.tsx +++ b/apps/infoalloggi/src/forms/FormLogin.tsx @@ -49,15 +49,25 @@ export const FormLogin = () => { onError: ({ message }) => { toast.error(`${t.auth.login.fail}\n${message}`); }, - onSuccess: async () => { - await utils.auth.getSession.invalidate(); - setAlreadyRequested(true); - toast.success(t.auth.login.success); - await router.push(redirect ? (redirect as string) : "/"); - //window.location.replace(redirect ? (redirect as string) : "/"); + onSuccess: async (data) => { + switch (data.status) { + case "not-found": + setUserNotFound(true); + toast.error(data.message); + return; + case "fail": + toast.error(data.message); + return; + case "success": + await utils.auth.getSession.invalidate(); + toast.success(t.auth.login.success); + await router.push(redirect ? (redirect as string) : "/"); + //window.location.replace(redirect ? (redirect as string) : "/"); + return; + } }, }); - const [altreadyRequested, setAlreadyRequested] = useState(false); + const [userNotFound, setUserNotFound] = useState(false); function onSubmit(fields: LoginFormValues) { mutate({ email: fields.email, @@ -89,123 +99,143 @@ export const FormLogin = () => { TEMP DEV LOGIN )} - -