fix(auth): show clear message instead of error code on login failure

This commit is contained in:
Utkarsh-X 2025-09-18 16:35:41 +05:30
parent 40b5161a52
commit 779ec599a2
2 changed files with 13 additions and 3 deletions

View file

@ -88,10 +88,16 @@ class CustomBearerTransport(BearerTransport):
else:
return JSONResponse(model_dump(bearer_response))
async def get_login_failure_response(self) -> Response:
# 👇 This is the new part — gives a clear message instead of raw error code
return JSONResponse(
status_code=401,
content={"detail": "Wrong username or password"},
)
bearer_transport = CustomBearerTransport(tokenUrl="auth/jwt/login")
auth_backend = AuthenticationBackend(
name="jwt",
transport=bearer_transport,

View file

@ -42,18 +42,22 @@ export function LocalLoginForm() {
const data = await response.json();
if (!response.ok) {
throw new Error(data.detail || "Failed to login");
// 👇 Instead of generic error, show backends message
setError(data.detail || "Wrong username or password");
return;
}
router.push(`/auth/callback?token=${data.access_token}`);
} catch (err) {
const errorMessage = err instanceof Error ? err.message : "An error occurred during login";
const errorMessage =
err instanceof Error ? err.message : "An error occurred during login";
setError(errorMessage);
} finally {
setIsLoading(false);
}
};
return (
<div className="w-full max-w-md">
<form onSubmit={handleSubmit} className="space-y-4">