Skip to content

[BUG] Login and Signup pages always show generic error due to swallowed exceptions in AuthContext #96

Description

@Pratyush-Panda-2006

Description
In
AuthContext.jsx
, the login and register functions catch any HTTP errors thrown by the Axios client, print them to the console, and return false.

Consequently, the try...catch blocks inside
Login.jsx
and
Signup.jsx
are unable to catch these errors. The pages always fall back to rendering a generic error message ("Login failed. Please check your credentials" or "Registration failed. Please try again") instead of the correct context-specific messages (e.g., "Account not found", "Server error", "User already exists").

Impact
Poor UX: Users get misleading or generic feedback when a login/signup attempt fails due to specific reasons (e.g., database connectivity failures or server-side crashes).
Unreachable Code: Detailed status check blocks (err.response?.status) in both Login.jsx and Signup.jsx are dead code.
Location in Code
AuthContext.jsx
:
javascript

const login = async (userData) => {
try {
const response = await api.post("/auth/login", userData);
// ...
} catch (error) {
console.error("Login API error:", error);
return false; // Error is swallowed and not thrown
}
};
Login.jsx
:
javascript

try {
const success = await login({ email, password });
if (success) {
navigate("/home");
} else {
setError("Login failed. Please check your credentials."); // Always triggers this
}
} catch (err) {
// Unreachable catch block
const statusCode = err.response?.status;
// ...
}

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions