Update page.tsx

This commit is contained in:
NotII
2025-03-23 22:21:27 +00:00
parent 654b0587fe
commit fb0fc7b132

View File

@@ -40,7 +40,17 @@ export default function LoginPage() {
body: JSON.stringify({ username, password }),
});
const data = await response.json();
let data;
try {
data = await response.json();
} catch (parseError) {
console.error("Login parse error:", parseError);
toast.error("Server Error", {
description: "The server response couldn't be processed. Please try again."
});
setIsLoading(false);
return;
}
if (response.ok && data.token) {
// Store the token in both cookie and localStorage for redundancy
@@ -53,16 +63,17 @@ export default function LoginPage() {
router.push(redirectUrl);
} else {
// Handle HTTP error responses
const errorMessage = data.error || "Invalid credentials";
const errorMessage = data.error || data.message || data.details || "Invalid credentials";
toast.error("Login Failed", {
description: errorMessage,
});
console.error("Login error response:", { status: response.status, data });
}
} catch (error) {
toast.error("Connection Error", {
description: "Unable to connect to the server. Please check your internet connection and try again.",
});
console.error("Login error:", error);
console.error("Login network error:", error);
} finally {
setIsLoading(false);
}