Skip to content

feat: add provisioning API signup flow for new users#377

Open
MattBro wants to merge 7 commits intomainfrom
matt/provisioning-signup-flow
Open

feat: add provisioning API signup flow for new users#377
MattBro wants to merge 7 commits intomainfrom
matt/provisioning-signup-flow

Conversation

@MattBro
Copy link
Copy Markdown
Contributor

@MattBro MattBro commented Apr 6, 2026

Problem

When users run the wizard with --signup, it opens a browser to posthog.com/signup. This requires browser access and creates friction for CLI-first workflows. Users should be able to create a PostHog account entirely from the terminal.

Changes

  • New src/utils/provisioning.ts - client for the agentic provisioning API using PKCE auth
  • Modified src/utils/setup-utils.ts - when --signup is used with --email, creates account via provisioning API instead of browser OAuth
  • Falls back to browser login if email already has an account
  • Added --email CLI arg and session field

How the PKCE flow works

  1. User runs npx @posthog/wizard --signup --email user@example.com
  2. Calls POST /api/agentic/provisioning/account_requests with PKCE code_challenge
  3. Exchanges auth code for tokens via POST /api/agentic/oauth/token with code_verifier
  4. Provisions resources via POST /api/agentic/provisioning/resources
  5. Returns API key, host, and PAT - no browser needed

Future UX improvement

We should experiment with removing the --signup flag entirely and auto-detecting: if the wizard has no credentials, ask "Create account or log in?" and prompt for email inline. This would make the default npx @posthog/wizard flow work for new users without any flags. Keeping --email as a CI shortcut.

How did you test this code?

Tested end-to-end against local PostHog dev server running PostHog/posthog#53493 (server-side provisioning changes):

1. Creating account for wizard-e2e-1775507021378@example.com
   Type: oauth
   Code: cSTZJ3WKp7...
2. Exchanging code for tokens (PKCE)
   access_token: pha_tgo2GVzm9P4...
   expires_in: 3600 seconds
3. Provisioning resources
   Status: complete
   API key: phc_Bo4ZEg69nNp...
   Host: https://us.posthog.com
   PAT: phx_FCm3bWn9Unx...

SUCCESS: Full wizard PKCE provisioning flow works end-to-end!

Agent-authored: full e2e test above was run, but no manual interactive TUI testing yet.

Depends on

PostHog/posthog#53493 (server-side ProvisioningPartner model + PKCE support)

Publish to changelog?

No (not ready yet - needs server-side PR merged first)

🤖 LLM context

Co-authored with Claude Code. Part of Slice 1 of the generic provisioning spec - making agentic provisioning multi-tenant so the wizard can create accounts via PKCE.

When --signup is used, the wizard now creates a PostHog account via the
agentic provisioning API with PKCE auth instead of opening a browser.
Prompts for email in the terminal, then calls account_requests ->
oauth/token -> resources to get credentials without any browser redirect.

Falls back to browser OAuth login if the email already has an account.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

🧙 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 android
  • /wizard-ci angular
  • /wizard-ci astro
  • /wizard-ci django
  • /wizard-ci fastapi
  • /wizard-ci flask
  • /wizard-ci javascript-node
  • /wizard-ci javascript-web
  • /wizard-ci laravel
  • /wizard-ci next-js
  • /wizard-ci nuxt
  • /wizard-ci python
  • /wizard-ci rails
  • /wizard-ci react-native
  • /wizard-ci react-router
  • /wizard-ci sveltekit
  • /wizard-ci swift
  • /wizard-ci tanstack-router
  • /wizard-ci tanstack-start
  • /wizard-ci vue

Test an individual app:

  • /wizard-ci android/Jetchat
  • /wizard-ci angular/angular-saas
  • /wizard-ci astro/astro-hybrid-marketing
Show more apps
  • /wizard-ci astro/astro-ssr-docs
  • /wizard-ci astro/astro-static-marketing
  • /wizard-ci astro/astro-view-transitions-marketing
  • /wizard-ci django/django3-saas
  • /wizard-ci fastapi/fastapi3-ai-saas
  • /wizard-ci flask/flask3-social-media
  • /wizard-ci javascript-node/express-todo
  • /wizard-ci javascript-node/fastify-blog
  • /wizard-ci javascript-node/hono-links
  • /wizard-ci javascript-node/koa-notes
  • /wizard-ci javascript-node/native-http-contacts
  • /wizard-ci javascript-web/saas-dashboard
  • /wizard-ci laravel/laravel12-saas
  • /wizard-ci next-js/15-app-router-saas
  • /wizard-ci next-js/15-app-router-todo
  • /wizard-ci next-js/15-pages-router-saas
  • /wizard-ci next-js/15-pages-router-todo
  • /wizard-ci nuxt/movies-nuxt-3-6
  • /wizard-ci nuxt/movies-nuxt-4
  • /wizard-ci python/meeting-summarizer
  • /wizard-ci rails/fizzy
  • /wizard-ci react-native/expo-react-native-hacker-news
  • /wizard-ci react-native/react-native-saas
  • /wizard-ci react-router/react-router-v7-project
  • /wizard-ci react-router/rrv7-starter
  • /wizard-ci react-router/saas-template
  • /wizard-ci react-router/shopper
  • /wizard-ci sveltekit/CMSaasStarter
  • /wizard-ci swift/hackers-ios
  • /wizard-ci tanstack-router/tanstack-router-code-based-saas
  • /wizard-ci tanstack-router/tanstack-router-file-based-saas
  • /wizard-ci tanstack-start/tanstack-start-saas
  • /wizard-ci vue/movies

Results will be posted here when complete.

- Replace readline prompt with --email CLI arg (avoids TUI/stdin conflict)
- Add 30s request timeouts to all provisioning API calls
- Use parseInt instead of Number for projectId
- Thread email through session -> getOrAskForProjectData -> askForProvisioningSignup
- Add email to WizardOptions type and CLI args

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@MattBro MattBro marked this pull request as ready for review April 6, 2026 21:19
@MattBro MattBro requested review from a team, fercgomes, joshsny and rafaeelaudibert April 6, 2026 21:19
Copy link
Copy Markdown
Member

@edwinyjlim edwinyjlim left a comment

Choose a reason for hiding this comment

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

oh hell yeah, top of funnel is getting exciting!

@MattBro i'm assuming the PKCE and account provisioning API endpoints aren't merged to the monorepo yet?

if the wizard has no credentials, ask "Create account or log in?" and prompt for email inline

for sure, we can build the UX/UI sign up flow in the TUI once that you have all the auth plumbing deployed

MattBro and others added 4 commits April 8, 2026 10:00
6 tests covering: full PKCE flow, existing account handling, API errors,
resource provisioning failure, region parameter, request timeouts.
Also fixes missing timeout on resources request.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
buildSession in the TUI path was missing the email arg, so
--signup --email would fail in interactive mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Was using POSTHOG_DEV_CLIENT_ID in dev mode which doesn't match the
ProvisioningPartner record created by the data migration. The
provisioning client_id is always 'posthog-wizard' regardless of env.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Wire --region parameter through to provisioning (was hardcoded to US)
- Add NaN guard on parseInt for projectId
- Region threaded: CLI arg -> session -> getOrAskForProjectData -> provisionNewAccount

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@edwinyjlim edwinyjlim left a comment

Choose a reason for hiding this comment

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

let's goo

feel free to merge once the monorepo endpoints are live

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.

2 participants