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 }), 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) { if (response.ok && data.token) {
// Store the token in both cookie and localStorage for redundancy // Store the token in both cookie and localStorage for redundancy
@@ -53,16 +63,17 @@ export default function LoginPage() {
router.push(redirectUrl); router.push(redirectUrl);
} else { } else {
// Handle HTTP error responses // Handle HTTP error responses
const errorMessage = data.error || "Invalid credentials"; const errorMessage = data.error || data.message || data.details || "Invalid credentials";
toast.error("Login Failed", { toast.error("Login Failed", {
description: errorMessage, description: errorMessage,
}); });
console.error("Login error response:", { status: response.status, data });
} }
} catch (error) { } catch (error) {
toast.error("Connection Error", { toast.error("Connection Error", {
description: "Unable to connect to the server. Please check your internet connection and try again.", 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 { } finally {
setIsLoading(false); setIsLoading(false);
} }