Skip to content

[feature] replace bare 403 with a sign-in / switch-account page - #9

Merged
YJack0000 merged 1 commit into
mainfrom
feature/access-page
Oct 5, 2026
Merged

YJack0000 merged 1 commit into
mainfrom
feature/access-page

Conversation

@YJack0000

Copy link
Copy Markdown
Contributor

問題

沒登入、或登入的帳號不是 workspace 成員時,文件頁只回一行純文字 forbidden,workspace 頁回 404,使用者完全不知道該怎麼辦。

改了什麼

  • 文件頁(/o/[slug]/d/...)、workspace、members、settings 頁沒有權限時,一律導到新的 /access?next=<原本路徑>。
  • /access 分兩種狀態:
    • 沒登入:顯示「登入以繼續」+ Google 登入,登入後回到原本的頁面。
    • 登入了但不是成員:顯示目前登入的 email,提供「換一個帳號登入」(先登出再開 Google 帳號選擇)、「登出」,並列出這個帳號能進的 workspace。
  • /access 同時是登入後的 callback:如果選的帳號還是沒權限,會回到這頁看到原因,不會又撞一次死路。
  • Google provider 加 prompt: "select_account",每次登入都出現帳號選擇器;不然登出後再登入,Google 會直接用同一個帳號登回來,換不了帳號。
  • 文件在 workspace 殼裡以 ?embed=1 iframe 開時 session 過期,/access 會跳出 iframe(Google 不允許在 iframe 裡登入)。導過去時會拿掉 ?embed=1。
  • next 只接受站內路徑(擋 //host、/\host),避免 open redirect。
  • /api/* 的 JSON 403 不變。

驗證

  • next build、tsc --noEmit 通過。
  • 本機 next start、沒登入:/o/jack-db85、/o/jack-db85/settings → 307 到 /access?next=…;/o/jack-db85/d/pathors/x?embed=1 → 302 到 /access?next=%2Fo%2Fjack-db85%2Fd%2Fpathors%2Fx(embed 已拿掉);/access?next=//evil.com 被當成 /。
  • 「已登入但不是成員」的畫面用暫時的 preview page 帶假資料看過版面(未 commit);真實登入流程要部署後實測。

Member-gated pages answered a signed-out or wrong-account visitor with a
plain-text "forbidden" (documents) or a 404 (workspace pages), leaving no way
forward. They now redirect to /access, which:

- signed out: offers Google sign-in and returns to the original page
- signed in as a non-member: shows the current email, offers switching
  account or signing out, and lists the workspaces this account can open

/access is also the post-login callback, so picking another wrong account
lands back on the explanation instead of a dead end. The Google provider now
always shows the account chooser; otherwise signing out to switch would
silently sign the same account back in.

next is restricted to same-origin paths to avoid an open redirect.
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

✅ SonarQube Quality Gate passed — pathorsAI_pensieve

0 open issues on this PR.

@YJack0000
YJack0000 merged commit 3e4b5d0 into main Oct 5, 2026
1 check passed
@YJack0000
YJack0000 deleted the feature/access-page branch October 5, 2026 07:11
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.

1 participant