PAB-36: support auth on Vercel previews#100
Merged
Merged
Conversation
Co-authored-by: multica-agent <github@multica.ai>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: multica-agent <github@multica.ai>
pablopunk
marked this pull request as ready for review
July 12, 2026 14:37
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Co-authored-by: multica-agent <github@multica.ai>
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.
Summary
This PR adds authentication support for Vercel preview deployments, which previously couldn't complete OAuth sign-in because the WorkOS redirect URI is fixed to the production callback (
https://nvm.fyi/api/auth/callback).How it works
The implementation introduces a secure, short-lived handoff mechanism between the production callback and preview deployments:
Sign-in detection (
signin.ts): When a sign-in request originates from a recognized Vercel preview hostname (matching the project's deployment pattern), the OAuthstateparameter is replaced with a signed, one-time preview state token (stored in Upstash Redis with a 60-second TTL) that encodes the preview origin and return path.Production callback (
callback.ts): After WorkOS authentication completes, if the state decodes as a preview state, the callback does not set a session cookie on the production domain. Instead, it creates an encrypted session grant (a short-lived encrypted JWT containing the sealed session) and redirects the user to the preview deployment's/api/auth/preview-exchangeendpoint.Preview exchange (
preview-exchange.ts): A new endpoint on the preview deployment that validates the grant is intended for its own origin, then sets the session cookie directly on the preview hostname and redirects to the return path.Security measures
getdel).Other changes
preview-auth.ts: New library implementing preview state encoding/decoding and session grant creation/consumption usingjosefor JWT signing/encryption and Upstash Redis for state storage.preview-auth.test.ts: Unit tests covering preview domain validation, grant round-tripping, malformed state rejection, and foreign deployment rejection.README.md: Documents the preview auth flow, security model, and deployment guidance (scoping secrets to trusted preview branches, keeping fork protection enabled).