mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
fix(auth): show clear message instead of error code on login failure
This commit is contained in:
parent
40b5161a52
commit
779ec599a2
2 changed files with 13 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 backend’s 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">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue