Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return 401 for login failures #15432

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frigate/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def login(request: Request, body: AppPostLoginBody):
try:
db_user: User = User.get_by_id(user)
except DoesNotExist:
return JSONResponse(content={"message": "Login failed"}, status_code=400)
return JSONResponse(content={"message": "Login failed"}, status_code=401)

password_hash = db_user.password_hash
if verify_password(password, password_hash):
Expand All @@ -340,7 +340,7 @@ def login(request: Request, body: AppPostLoginBody):
response, JWT_COOKIE_NAME, encoded_jwt, expiration, JWT_COOKIE_SECURE
)
return response
return JSONResponse(content={"message": "Login failed"}, status_code=400)
return JSONResponse(content={"message": "Login failed"}, status_code=401)


@router.get("/users")
Expand Down
7 changes: 5 additions & 2 deletions web/src/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export function ApiProvider({ children, options }: ApiProviderType) {
error.response &&
[401, 302, 307].includes(error.response.status)
) {
window.location.href =
error.response.headers.get("location") ?? "login";
// redirect to the login page if not already there
const loginPage = error.response.headers.get("location") ?? "login";
if (window.location.href !== loginPage) {
window.location.href = loginPage;
}
}
},
...options,
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/auth/AuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
toast.error("Exceeded rate limit. Try again later.", {
position: "top-center",
});
} else if (err.response?.status === 400) {
} else if (err.response?.status === 401) {
toast.error("Login failed", {
position: "top-center",
});
Expand Down
Loading