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); }