docs(auth): add OAuth PKCE callback flow documentation#23
Conversation
- sdk-integration.md: Add two redirect URLs table, SPA vs SSR split, SDK methods reference for signInWithOAuth and exchangeOAuthCode - ssr-integration.md: Replace bullet-point best practices with full Next.js implementation (server action + API route + login page), trailing slash safe URL construction, expanded common mistakes Addresses user confusion where redirectTo pointed to the InsForge backend instead of the frontend app, causing "Cannot GET /auth/callback". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalkthroughDocumentation updates for InsForge OAuth integration, clarifying PKCE support, redirect URL semantics, and SDK method usage. SPA examples updated to show client-side code auto-detection. SSR/Next.js guidance expanded with server action and API route examples for full server-side OAuth flow with secure cookie handling. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@skills/insforge/auth/ssr-integration.md`:
- Around line 156-157: The redirect currently interpolates raw backend text via
exchangeError?.message into the query string in NextResponse.redirect; change it
to pass either a stable error code or a sanitized/URL-encoded message instead of
raw text—locate the redirect line that constructs new
URL(`/login?error=${exchangeError?.message ?? 'exchange_failed'}`, request.url)
and replace it with logic that maps exchangeError to a deterministic code (or
applies safe encoding like URL-encoding) and use that value in the query
parameter so URLs remain valid and internals are not exposed.
- Around line 110-120: Guard against a missing PKCE verifier instead of using a
non-null assertion: after validating error and data.url in the OAuth init block,
also explicitly check that data.codeVerifier exists (e.g., if
(!data.codeVerifier) throw new Error('Missing codeVerifier for PKCE')) before
calling cookies() and cookieStore.set('insforge_code_verifier', ...). Update the
check that currently throws for error || !data.url to also validate
data.codeVerifier and use that validated value when calling cookieStore.set to
avoid relying on the non-null assertion on data.codeVerifier.
🪄 Autofix (Beta)
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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4be52fe9-9ce7-4c27-9bfb-074f66f50697
📒 Files selected for processing (2)
skills/insforge/auth/sdk-integration.mdskills/insforge/auth/ssr-integration.md
|
cc @Fermionic-Lyu can you check this for me? giving more guidance in skills to fix callback url incorrect issue |
Fermionic-Lyu
left a comment
There was a problem hiding this comment.
LGTM in quick scan. Can fix wording later if doesn't work well
| | OAuth provider callback | InsForge backend (`https://<project>.insforge.app/api/auth/oauth/<provider>/callback`) | Google Console, GitHub OAuth app, etc. | | ||
| | `redirectTo` | **Your app** (`https://yourapp.com/auth/callback`) | Passed in `signInWithOAuth()` | | ||
|
|
||
| `redirectTo` is where the user lands after auth. The backend appends `?insforge_code=<code>` to it. If this points to the backend instead of your app, you get `Cannot GET /auth/callback`. |
There was a problem hiding this comment.
This is technically correct but I am not sure if it is a good practice to include it in the skill
Summary
let agent to optmizae the experience for auth
redirectTo), SPA vs SSR guidance, SDK methods reference forsignInWithOAuthandexchangeOAuthCode/api/auth/callbackroute handler, login page component, trailing-slash-safe URL constructionProblem
Users were setting
redirectToto the InsForge backend URL (NEXT_PUBLIC_INSFORGE_URL) instead of their app URL (NEXT_PUBLIC_APP_URL), causingCannot GET /auth/callback. The skill docs didn't explain the distinction or show the full SSR callback flow.Testing
Test plan
redirectTo, callback route, exchange flow🤖 Generated with Claude Code
Note
Add OAuth PKCE callback flow documentation for SPA and SSR environments
redirectTo(app URL), with a commonCannot GET /auth/callbackerror callout.insforge_codedetection and URL cleanup.skipBrowserRedirect: true, an API route handler that exchanges the code and setshttpOnlycookies, and a client login component.signInWithOAuth,skipBrowserRedirect, andexchangeOAuthCode.redirectTousage,codeVerifierstorage, and server-side token handling.Macroscope summarized 7dcfb4c.
Summary by CodeRabbit