Unified · Split
| @@ -21,6 +21,26 @@ function readOptionalQueryParam(request: NextRequest, keys: string[]): string | · 20 unmodified lines | ||
| 21 | 21 | return undefined; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | +const AUTHKIT_PASSTHROUGH_QUERY_KEYS = [ | |
| 25 | + "authorization_session_id", | |
| 26 | + "redirect_uri", | |
| 27 | + "state", | |
| 28 | +]; | |
| 29 | + | |
| 30 | +function appendAuthkitPassthroughQueryParams(request: NextRequest, authorizationUrl: string): string { | |
| 31 | + const nextUrl = new URL(authorizationUrl); | |
| 32 | + | |
| 33 | + for (const key of AUTHKIT_PASSTHROUGH_QUERY_KEYS) { | |
| 34 | + const value = request.nextUrl.searchParams.get(key); | |
| 35 | + if (!value || value.trim().length === 0) { | |
| 36 | + continue; | |
| 37 | + } | |
| 38 | + nextUrl.searchParams.set(key, value.trim()); | |
| 39 | + } | |
| 40 | + | |
| 41 | + return nextUrl.toString(); | |
| 42 | +} | |
| 43 | + | |
| 24 | 44 | const convexUrl = process.env.NEXT_PUBLIC_CONVEX_URL ?? process.env.CONVEX_URL; |
| 25 | 45 | const convexClient = convexUrl ? new ConvexHttpClient(convexUrl) : null; |
| 26 | 46 | |
| @@ -65,10 +85,11 @@ export async function GET(request: NextRequest) { · 38 unmodified lines | ||
| 65 | 85 | const loginHint = readOptionalQueryParam(request, ["loginHint", "login_hint", "email"]); |
| 66 | 86 | |
| 67 | 87 | const { getSignUpUrl } = await import("@workos-inc/authkit-nextjs"); |
| 68 | − const authorizationUrl = await getSignUpUrl({ | |
| 88 | + const baseAuthorizationUrl = await getSignUpUrl({ | |
| 69 | 89 | redirectUri, |
| 70 | 90 | organizationId, |
| 71 | 91 | loginHint, |
| 72 | 92 | }); |
| 93 | + const authorizationUrl = appendAuthkitPassthroughQueryParams(request, baseAuthorizationUrl); | |
| 73 | 94 | return redirect(authorizationUrl); |
| 74 | 95 | } |