Skip to content

fix: make OAuth refresh_token optional to unblock wizard login#467

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/oauth-optional-refresh-token
Draft

fix: make OAuth refresh_token optional to unblock wizard login#467
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/oauth-optional-refresh-token

Conversation

@posthog
Copy link
Copy Markdown

@posthog posthog Bot commented May 21, 2026

Problem

Wizard login hard-aborts for any user whose OAuth token response from POSTHOG_OAUTH_URL/oauth/token omits refresh_token. OAuthTokenResponseSchema declared the field required, so OAuthTokenResponseSchema.parse in exchangeCodeForToken throws ZodError: refresh_token Required, the catch in performOAuthFlow calls abort(), and the wizard run dies at its entry point with no workaround.

Error tracking shows this across at least 4 distinct users on two separate wizard releases (bundle hashes setup-utils-BYMsvp-X.js and setup-utils-DGUR4Djo.js), spanning 2026-04-30 through 2026-05-21 — so it reproduces across users and releases.

Changes

src/utils/oauth.ts:51 — mark refresh_token as z.string().optional().

performOAuthFlow's result is consumed only at src/utils/setup-utils.ts:488, which reads access_token and scoped_teams; nothing downstream persists or uses the refresh token, so propagating string | undefined is safe (the inferred OAuthTokenResponse type updates automatically).

The separate TokenResponseSchema in src/utils/provisioning.ts (used by the provisioning signup flow, not the OAuth login flow) is unchanged — that code path forwards refresh_token into its return value and is governed by a different server endpoint that does issue refresh tokens.

Test plan

  • pnpm build — clean
  • pnpm test for src/__tests__/provision-cli.test.ts and provisioning suites — passing (one flaky full-suite timeout in provision-cli.test.ts reproduces on main too and is unrelated to this change)
  • pnpm lint — no new errors
  • Manual: re-run the wizard against an OAuth token response that omits refresh_token and confirm login completes

Created with PostHog Code

The OAuth token endpoint does not always issue a refresh_token, but the
schema marked it required, so parse() threw synchronously inside
exchangeCodeForToken and aborted the entire wizard run during login.

The performOAuthFlow result is consumed only for access_token and
scoped_teams (src/utils/setup-utils.ts:488), so loosening the schema is
safe.

Generated-By: PostHog Code
Task-Id: 9ee1d361-cf7f-4c33-8298-8f829cd4c6a0
@github-actions
Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci misc
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci misc/quack-quack
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

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.

0 participants