Update page.tsx
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user