From fb0fc7b1325178ead65f1665c881f0d151d0c2b6 Mon Sep 17 00:00:00 2001 From: NotII <46204250+NotII@users.noreply.github.com> Date: Sun, 23 Mar 2025 22:21:27 +0000 Subject: [PATCH] Update page.tsx --- app/auth/login/page.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/auth/login/page.tsx b/app/auth/login/page.tsx index 9b8fc7f..e3724d3 100644 --- a/app/auth/login/page.tsx +++ b/app/auth/login/page.tsx @@ -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); }