Skip to content

Redirect unauthorized users to /login#1

Merged
localzet merged 1 commit into
mainfrom
feat/redirect-to-login-on-error
Apr 30, 2026
Merged

Redirect unauthorized users to /login#1
localzet merged 1 commit into
mainfrom
feat/redirect-to-login-on-error

Conversation

@localzet

Copy link
Copy Markdown
Owner

Motivation

  • When unauthenticated requests hit protected admin routes the app rendered a 401 HTML error page; instead users should be sent to the login screen to improve UX.

Description

  • Update src/error.rs so AppError::into_response returns Redirect::to("/login") for AppError::Unauthorized, and add the Redirect import from axum::response.

Testing

  • Ran formatting and type checks: cargo fmt --all and cargo check, both completed successfully.

Codex Task

@localzet
localzet merged commit e7814e2 into main Apr 30, 2026
1 check passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a44cee98a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/error.rs
Comment on lines +52 to +54
if matches!(self, AppError::Unauthorized) {
return Redirect::to("/login").into_response();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep API auth failures as 401 instead of redirecting

This unconditional redirect changes every AppError::Unauthorized into a 303 /login, including API handlers in src/routes/api.rs that call auth::require_admin. Because fetch follows redirects, the admin frontend (static/admin-app.js) receives a 200 HTML login page and then fails at response.json() (or misclassifies auth loss as a generic parse error) when a session expires, instead of getting a clean 401 auth failure signal.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant