Conversation
…CALLBACK_URL OpenNext 的 redirect matcher 只在 source 抓到參數時才會代換 destination。 `/:segment/:path*` 對沒有子路徑的網址抓到零段,destination 原字照回; 沒登入時這串被帶進 /login 的 callbackURL,better-auth 驗不過。 拆成 `/segment` 與 `/segment/:path+` 兩條。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@yui0303 AI check 沒問題,可以 review/merge 🙏 (只改 next.config.ts 的 redirects,修舊網址 /settings 等登入時的 INVALID_CALLBACK_URL;已用 cf:build + wrangler 本機驗過) |
✅ SonarQube Quality Gate passed — pathorsAI_internal0 open issues on this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
從舊網址(例如
https://internal.pathors.com/settings)進站登入時,Google 登入按下去直接跳「Invalid callbackURL」。prod 現況:
/settings/dashboard/settings/:path*❌(字面上的:path*)/contracts/dashboard/contracts/:path*❌/settings/foo/dashboard/settings/foo✅MOVED_TO_DASHBOARD裡的 18 個頁面,只要舊網址後面沒接子路徑就都會壞掉。原因
redirects()規則是 [feature] 邀請過期可見化、MCP 上架 metadata、landing page 與 /dashboard 搬移、交易幣別綁定帳戶 #49 搬/dashboard時加的:/${segment}/:path*→/dashboard/${segment}/:path*。照 Next 的規格沒寫錯。@opennextjs/aws的 matcher(core/routing/matcher.js)只有在 source 抓到至少一個參數時(isUsingParams)才會把 destination 丟進compile()。/settings的:path*抓到零段,沒有參數,destination 就原字照回。:和*,於是回INVALID_CALLBACK_URL。Google OAuth client 這邊沒有問題:prod 產生的 authorize URL 實際打過,沒有
redirect_uri_mismatch。改動
next.config.ts:每個頁面拆成兩條規則。/${segment}→/dashboard/${segment}:沒有參數,不需要代換。/${segment}/:path+→/dashboard/${segment}/:path+:至少一段,一定有參數,一定會被代換。驗證
跑
bun run cf:build,再用wrangler dev --local起 build 好的 worker 實測:/settings/dashboard/settings✅/settings/foo/dashboard/settings/foo✅/contracts/dashboard/contracts✅/contracts/123/edit/dashboard/contracts/123/edit✅/dashboard/settings(未登入)/login?redirect=%2Fdashboard%2Fsettings✅/dashboard/...。🤖 Generated with Claude Code