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;
// ...
}
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;
// ...
}