Skip to content

fix(web): 注册页补充已登录重定向守卫,与登录页 / classic 主题保持一致 (#5908) - #5910

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
Heykode:fix/signup-authed-redirect
Jul 6, 2026
Merged

fix(web): 注册页补充已登录重定向守卫,与登录页 / classic 主题保持一致 (#5908)#5910
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
Heykode:fix/signup-authed-redirect

Conversation

@Heykode

@Heykode Heykode commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

📝 变更描述 / Description

default 主题下,登录页 /sign-in 的 route 已在 beforeLoad 中做了"已登录则重定向到 /dashboard"的守卫,但注册页 /sign-up(以及其别名 /register,后者仅 throw redirect/sign-up)没有等价守卫,导致已登录用户访问注册页时停在注册表单,而非进入主界面。

本 PR 在 sign-up.tsx 的 route 增加与 sign-in.tsx 一致的 beforeLoad 守卫:沿用同一 useAuthStore 判断登录态,已登录时 throw redirect({ to: '/dashboard' })。守卫加在实际渲染注册页的 /sign-up,因此 /register/sign-up 两个入口都被覆盖。该行为与旧 classic 主题 web/classic/src/helpers/auth.jsxAuthRedirect/register 的处理一致。

说明:这不是 rc.13→rc.16 之间的代码回归(两个 tag 的该路由文件除格式化外无功能差异,/sign-up 守卫在 default 前端自 v1.0 起从未存在),因此作为"行为一致性补齐"提交,归类为 Refactor / 一致性修复而非 Bug。

🚀 变更类型 / Type of change

  • ⚡ 性能优化 / 重构 (Refactor) - 补齐注册页与登录页 / classic 主题一致的已登录重定向行为

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述。(另见下方 AI 协助声明)
  • 非重复提交: 我已搜索现有 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 本 PR 未标记为 Bug fix;已如实说明这是行为一致性补齐而非回归。
  • 变更理解: 我已理解这些更改的工作原理及影响。
  • 范围聚焦: 本 PR 仅改动 sign-up.tsx 一处,逻辑复用现有 sign-in.tsx 模式,无无关改动。
  • 本地验证: 已本地 bun run typecheck 通过;bunx oxlint 对本文件零 error;format:check 通过。
  • 安全合规: 无敏感凭据,符合项目规范。

📸 运行证明 / Proof of Work

  • 对照实现:web/default/src/routes/(auth)/sign-in.tsx:32-41 已有等价守卫(跳 /dashboard)。
  • 本 PR diff(sign-up.tsx):新增 redirect / useAuthStore import,并在 route 增加 beforeLoad
    beforeLoad: async () => {
      const { auth } = useAuthStore.getState()
      // 如果已经有用户信息,说明已登录,注册页对其无意义,跳转到 dashboard
      if (auth.user) {
        throw redirect({ to: '/dashboard' })
      }
    },
  • 本地校验:bun run typecheck(tsgo -b)通过;bunx oxlint -c .oxlintrc.json "src/routes/(auth)/sign-up.tsx" 零 error;format 检查通过。

AI 协助声明: 本 PR 的问题定位、根因分析与代码改动在 AI(Claude)辅助下完成,所有结论均经源码与 git 历史核对,并已本地 typecheck / lint 验证。提交者非本仓库历史核心开发者,特此声明。

Summary by CodeRabbit

  • Bug Fixes
    • Signed-in users are now redirected away from the sign-up page to the dashboard.
    • Prevents authenticated users from accessing a page meant for new account creation.

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4dd4c4a-9f56-4023-ba48-69c3f5ec5eab

📥 Commits

Reviewing files that changed from the base of the PR and between 1ae7574 and ebdbd96.

📒 Files selected for processing (1)
  • web/default/src/routes/(auth)/sign-up.tsx

Walkthrough

The sign-up route in the default theme adds a beforeLoad guard that checks authentication state via useAuthStore and redirects already-authenticated users to /dashboard, aligning its behavior with the existing sign-in route.

Changes

Sign-up authentication guard

Layer / File(s) Summary
Add beforeLoad redirect guard
web/default/src/routes/(auth)/sign-up.tsx
Imports redirect and useAuthStore; adds an async beforeLoad hook that throws a redirect to /dashboard if auth.user is present.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Poem

A bunny hops to sign-up's door,
But finds a guard it hadn't before—
"Already in?" the guard will say,
"Then hop along to dashboard, stray!" 🐇
One small check, one tidy fix,
Consistency in the mix!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the sign-up redirect guard added for logged-in users and matches the main change.
Linked Issues check ✅ Passed The change satisfies #5908 by adding an authenticated-user redirect on the default theme sign-up route to /dashboard.
Out of Scope Changes check ✅ Passed The PR is narrowly scoped to the requested sign-up auth redirect and introduces no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Calcium-Ion
Calcium-Ion merged commit 3a876d6 into QuantumNous:main Jul 6, 2026
2 checks passed
52assert added a commit to 52assert/new-api that referenced this pull request Jul 7, 2026
…codes

* origin/main: (180 commits)
  fix(billing): extend quantity validation and saturating conversions to remaining paths
  fix(billing): validate quantity parameters and harden quota calculations
  Fix/build date dns error (QuantumNous#5945)
  fix: avoid stale stream writes after client disconnect (QuantumNous#5710)
  feat(group): enhance group ratio editor with improved visibility rules and JSON parsing
  feat: optimize legacy top-up warning banner copy (QuantumNous#5851) (QuantumNous#5855)
  fix(web): redirect authenticated users away from sign-up page (QuantumNous#5910)
  feat(ssrf): implement SSRF protection in HTTP clients and validation functions
  feat(user): better messages for redeem failures
  fix(html): 修复 Shadow DOM 隔离渲染下深浅色模式无法自动切换的问题 (QuantumNous#5890)
  fix(web): sync home iframe theme and language (QuantumNous#5917)
  fix: 任务差额结算后 quota 和阿里视频时长优化 (QuantumNous#5923)
  fix(web): refine mobile user cards
  test(user): cover self-service password update guard
  feat(session): support opt-in Secure session cookies
  fix(auth): allow read-only access for non-disabled tokens
  fix(user): harden account email and password handling
  fix: align dynamic pricing style with log details dialog sections
  fix(channels): show field passthrough controls for Codex (QuantumNous#5902)
  fix(user): trim whitespace from username and validate input
  ...

# Conflicts:
#	controller/redemption.go
#	controller/user.go
#	model/option.go
#	model/redemption.go
#	model/user.go
#	web/default/src/features/auth/api.ts
#	web/default/src/features/redemption-codes/api.ts
#	web/default/src/features/redemption-codes/components/redemptions-provider.tsx
#	web/default/src/features/redemption-codes/components/redemptions-table.tsx
#	web/default/src/features/redemption-codes/constants.ts
#	web/default/src/hooks/use-sidebar-data.ts
#	web/default/src/i18n/static-keys.ts
#	web/default/src/routes/__root.tsx
liulixin-lex pushed a commit to liulixin-lex/xy-api that referenced this pull request Jul 7, 2026
…mNous#5910)

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908

Co-authored-by: 贺. <kuang@M1.local>
xiaomingchen pushed a commit to xiaomingchen/new-api that referenced this pull request Jul 10, 2026
…mNous#5910)

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908

Co-authored-by: 贺. <kuang@M1.local>
Jacobinwwey pushed a commit to Jacobinwwey/new-api that referenced this pull request Jul 11, 2026
…mNous#5910)

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908

Co-authored-by: 贺. <kuang@M1.local>
ruanhangjian pushed a commit to ruanhangjian/new-api that referenced this pull request Jul 11, 2026
…mNous#5910)

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908

Co-authored-by: 贺. <kuang@M1.local>
lizhongyi1209 pushed a commit to lizhongyi1209/new-api that referenced this pull request Jul 13, 2026
…mNous#5910)

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908

Co-authored-by: 贺. <kuang@M1.local>
(cherry picked from commit 3a876d6)
noah-wung pushed a commit to noah-wung/new-api that referenced this pull request Jul 17, 2026
…mNous#5910)

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908

Co-authored-by: 贺. <kuang@M1.local>
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
…mNous#5910)

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908

Co-authored-by: 贺. <kuang@M1.local>
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
…mNous#5910)

The sign-in route already redirects logged-in users to /dashboard in its
beforeLoad guard, but the sign-up route (and its /register alias) had no
such guard, leaving authenticated users on the registration form. This
mirrors the classic theme's AuthRedirect behavior. Add an equivalent
beforeLoad guard using the same useAuthStore, redirecting to /dashboard
for consistency with the sign-in route.

Closes QuantumNous#5908

Co-authored-by: 贺. <kuang@M1.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

default 主题注册页缺少已登录重定向守卫(与登录页 / classic 主题行为不一致)

2 participants