Skip to content

fix: preserve OAuth query through consent - #255

Merged
ecryptoguru merged 2 commits into
mainfrom
codex/oauth-query-handoff
Aug 9, 2026
Merged

fix: preserve OAuth query through consent#255
ecryptoguru merged 2 commits into
mainfrom
codex/oauth-query-handoff

Conversation

@ecryptoguru

@ecryptoguru ecryptoguru commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Passes the complete signed OAuth query from both workspace-selection and consent pages to Better Auth continuations. This prevents the provider from losing the authorization request during browser handoff.

Summary by CodeRabbit

  • Bug Fixes

    • Improved OAuth consent and workspace selection flows by consistently preserving request parameters across sign-in and consent steps.
    • Omitted undefined OAuth parameters from generated callback URLs to prevent malformed query strings.
  • Tests

    • Added coverage for OAuth query serialization, including signed fields, array values, and omitted undefined values.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ecryptoguru, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 72210aee-6559-40a9-adfb-094d3bc49e3c

📥 Commits

Reviewing files that changed from the base of the PR and between 381b5f4 and af12eba.

📒 Files selected for processing (1)
  • apps/web/src/app/oauth/oauth-query.test.ts
📝 Walkthrough

Walkthrough

The change adds a shared OAuth query serializer. The consent and workspace selection pages use it for redirects and component props. Tests verify array handling and omission of undefined values.

Changes

OAuth query serialization

Layer / File(s) Summary
Serialization helper and coverage
apps/web/src/app/oauth/oauth-query.ts, apps/web/src/app/oauth/oauth-query.test.ts
serializeOAuthQuery serializes string and array values, skips undefined values, and uses URL encoding. Tests cover these cases.
OAuth page integration
apps/web/src/app/oauth/consent/page.tsx, apps/web/src/app/oauth/select-workspace/page.tsx
Both pages serialize the full OAuth parameter set. Consent uses the result for the sign-in callback and form. Workspace selection passes it to OAuthWorkspacePicker.

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

Possibly related PRs

🚥 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 main change: preserving the OAuth query during the consent flow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/oauth-query-handoff

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/app/oauth/oauth-query.test.ts`:
- Around line 5-8: Update the test around serializeOAuthQuery to use a two-value
scope array and assert that both scope entries appear in the serialized query,
while preserving the absent-value omission assertion.

In `@apps/web/src/app/oauth/select-workspace/page.tsx`:
- Line 16: Update the unauthenticated redirect in the OAuth workspace selection
page to include an encoded callbackURL pointing back to /oauth/select-workspace
with the serialized oauthQuery, matching the callback pattern used by the
consent page and preserving the signed request through sign-in.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 56ad7e15-871c-4afb-b0d2-675bb9ceea6f

📥 Commits

Reviewing files that changed from the base of the PR and between 00ffcb5 and 381b5f4.

📒 Files selected for processing (4)
  • apps/web/src/app/oauth/consent/page.tsx
  • apps/web/src/app/oauth/oauth-query.test.ts
  • apps/web/src/app/oauth/oauth-query.ts
  • apps/web/src/app/oauth/select-workspace/page.tsx

Comment on lines +5 to +8
it("preserves the signed OAuth request while omitting absent values", () => {
expect(
serializeOAuthQuery({ client_id: "client", scope: ["lyrashield.read"], state: "state", absent: undefined })
).toBe("client_id=client&scope=lyrashield.read&state=state")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Test repeated query values.

The array contains one value, so this test passes even when the serializer drops later values. Use a two-value array and assert that both serialized entries remain.

Proposed test update
-      serializeOAuthQuery({ client_id: "client", scope: ["lyrashield.read"], state: "state", absent: undefined })
-    ).toBe("client_id=client&scope=lyrashield.read&state=state")
+      serializeOAuthQuery({
+        client_id: "client",
+        scope: ["lyrashield.read", "lyrashield.write"],
+        state: "state",
+        absent: undefined,
+      })
+    ).toBe("client_id=client&scope=lyrashield.read&scope=lyrashield.write&state=state")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("preserves the signed OAuth request while omitting absent values", () => {
expect(
serializeOAuthQuery({ client_id: "client", scope: ["lyrashield.read"], state: "state", absent: undefined })
).toBe("client_id=client&scope=lyrashield.read&state=state")
it("preserves the signed OAuth request while omitting absent values", () => {
expect(
serializeOAuthQuery({
client_id: "client",
scope: ["lyrashield.read", "lyrashield.write"],
state: "state",
absent: undefined,
})
).toBe("client_id=client&scope=lyrashield.read&scope=lyrashield.write&state=state")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/app/oauth/oauth-query.test.ts` around lines 5 - 8, Update the
test around serializeOAuthQuery to use a two-value scope array and assert that
both scope entries appear in the serialized query, while preserving the
absent-value omission assertion.

}) {
const params = await searchParams
const session = await getSession()
const oauthQuery = serializeOAuthQuery(params)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve the OAuth query for unauthenticated users.

When session is absent, Line 17 redirects to /sign-in without a callbackURL. The serialized query is discarded, so the user cannot return to /oauth/select-workspace with the signed request. Use the same encoded callback pattern as apps/web/src/app/oauth/consent/page.tsx.

Proposed fix
   const oauthQuery = serializeOAuthQuery(params)
-  if (!session) redirect("/sign-in")
+  if (!session)
+    redirect(`/sign-in?callbackURL=${encodeURIComponent(`/oauth/select-workspace?${oauthQuery}`)}`)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const oauthQuery = serializeOAuthQuery(params)
const oauthQuery = serializeOAuthQuery(params)
if (!session)
redirect(`/sign-in?callbackURL=${encodeURIComponent(`/oauth/select-workspace?${oauthQuery}`)}`)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/app/oauth/select-workspace/page.tsx` at line 16, Update the
unauthenticated redirect in the OAuth workspace selection page to include an
encoded callbackURL pointing back to /oauth/select-workspace with the serialized
oauthQuery, matching the callback pattern used by the consent page and
preserving the signed request through sign-in.

@ecryptoguru
ecryptoguru merged commit be97935 into main Aug 9, 2026
9 checks passed
@ecryptoguru
ecryptoguru deleted the codex/oauth-query-handoff branch August 9, 2026 00:47
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