Skip to content

Commit

Permalink
fix: show error message when login fails due to invalid credentials (#…
Browse files Browse the repository at this point in the history
…2265)

* fix: show error message when login fails due to invalid credentials

Fixes #2253

* Update src/components/Authentication/Kratos/KratosLogin.tsx

---------

Co-authored-by: Moshe Immerman <[email protected]>
  • Loading branch information
mainawycliffe and moshloop authored Sep 8, 2024
1 parent c773370 commit 36cb5fb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/Authentication/Kratos/KratosLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Link from "next/link";
import { useSearchParams } from "next/navigation";
import { useRouter } from "next/router";
import { useCallback, useEffect, useState } from "react";
import { toastError } from "../../Toast/toast";

type LoginCredentials = {
username: string;
Expand Down Expand Up @@ -116,14 +115,17 @@ const KratosLogin = () => {
updateLoginFlowBody: values
});
setLoginSuccessful(true);
console.log("Login successful");
push(String(returnTo || "/"));
} catch (error) {
console.error(error);
toastError((error as AxiosError).message);
if ((error as AxiosError).response?.status === 400) {
// Yup, it is!
setFlow((error as AxiosError).response?.data as any);
return;
}
handleError(error as AxiosError);
}
},
[flow, push, returnTo]
[flow?.id, handleError, push, returnTo]
);

useEffect(() => {
Expand Down Expand Up @@ -155,6 +157,7 @@ const KratosLogin = () => {
}
}, [flow, submitFlow, credentials]);


return (
<div className="w-96">
<ToasterWithCloseButton />
Expand Down

0 comments on commit 36cb5fb

Please sign in to comment.