From c94a846c0b5679c68d3b91d6f71be01844680698 Mon Sep 17 00:00:00 2001
From: hamster1963 <1410514192@qq.com>
Date: Mon, 21 Oct 2024 13:49:55 +0800
Subject: [PATCH] fix: error control
---
components/SignIn.tsx | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/components/SignIn.tsx b/components/SignIn.tsx
index bb69b8d..d0bea0b 100644
--- a/components/SignIn.tsx
+++ b/components/SignIn.tsx
@@ -12,6 +12,7 @@ export function SignIn() {
const [csrfToken, setCsrfToken] = useState("");
const [loading, setLoading] = useState(false);
+ const [errorState, setErrorState] = useState(false);
const router = useRouter();
@@ -36,16 +37,23 @@ export function SignIn() {
`password=${encodeURIComponent(formData.get('password') as string)}`,
].join('&');
- await fetch("/api/auth/callback/credentials", {
+ const res = await fetch("/api/auth/callback/credentials", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: urlEncodedData,
});
+
+ if (res.url.includes("error")) {
+ setLoading(false)
+ setErrorState(true)
+ } else {
+ setLoading(false)
+ setErrorState(false)
+ }
router.push("/");
router.refresh();
- setLoading(false)
};
return (
@@ -56,6 +64,11 @@ export function SignIn() {