Skip to content

feat(cli): opt-in Mockatoo GitHub sign-in addon for dev and tests - #1306

Open
tianhuil wants to merge 4 commits into
AmanVarshney01:mainfrom
mockatoo:mockatoo-dev-auth
Open

tianhuil wants to merge 4 commits into
AmanVarshney01:mainfrom
mockatoo:mockatoo-dev-auth

Conversation

@tianhuil

@tianhuil tianhuil commented Nov 13, 2026 •

Copy link
Copy Markdown

Summary

Implements #1305: an opt-in --addons mockatoo that adds GitHub sign-in to the Better Auth template, using a mock OAuth provider outside production.

// server auth template (only with --addons mockatoo)
-socialProviders: {},
+socialProviders: isProduction ? { github } : {},
+plugins: isProduction ? [...] : [mockGitHub(github), ...],

// Next.js sign-in form
+<Button>Continue with GitHub</Button>
  • Opt-in: defaults are unchanged; nothing loads unless the addon is selected.
  • Development and tests: sign-in goes through Mockatoo (free hosted mock of GitHub OAuth). No GitHub OAuth app or secrets needed; E2E tests sign in with a Mockatoo test account.
  • Production: unchanged — Better Auth's normal GitHub provider; the mock plugin isn't loaded. GitHub env vars are @required=forEnv(production) in the Varlock schema.
  • Scope: Next.js frontend, Better Auth, non-Convex backends.

Evidence

  • Before: email/password only; the first social sign-in needs a registered GitHub OAuth app and secrets before dev runs.
    After: create-better-t-stack --frontend next --auth better-auth --addons mockatoo scaffolds a "Continue with GitHub" button that works immediately in dev. Verified end-to-end today against a generated split-origin app (web on :3001, API server on :3002): Playwright drives the full flow — click the button → Mockatoo consent → callback on the API origin → back to the web app's /dashboard, signed in.
  • Checks on this branch: bun run check, bun run build:cli, and the CLI test suite (bun test ./test --timeout 30000) all pass; 112/112 tests. (At the default 5s timeout one test times out on main as well.)

Summary by CodeRabbit

  • New Features
    • Added Mockatoo as a selectable add-on in the Development & Testing category.
    • Generated projects using Better Auth can include GitHub sign-in. In development and tests, GitHub authentication is mocked; production uses GitHub credentials.
    • GitHub credential settings are included in generated projects and required only in production.
  • Compatibility
    • Mockatoo is supported with Next.js and Better Auth, except when using Convex.

A relative callbackURL resolves against the Better Auth server, which is a
separate origin from the web app in non-self backends, so sign-in landed on
the API server's /dashboard (404). Use the web app's origin.
@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

@tianhuil is attempting to deploy a commit to the Better T Stack Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Files ignored due to path filters: 1

  • packages/template-generator/src/templates.generated.ts is excluded by !**/*.generated.*
Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ab3bec5e-7d54-442c-8267-1d37141c0b36
Commits

Reviewing files that changed from the base of the PR and between 1b8e4bd and b951cd9.

Files ignored due to path filters: 1

  • packages/template-generator/src/templates.generated.ts is excluded by !**/*.generated.*

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Walkthrough

The change adds the Mockatoo addon to project configuration and CLI selection, and limits its supported stack. Generated projects receive Better Auth GitHub sign-in configuration, conditional environment variables, a development and test mock plugin, and a GitHub sign-in button.

Changes

Mockatoo GitHub sign-in

Layer / File(s) Summary
Addon contract and selection
packages/types/src/schemas.ts, packages/types/src/compatibility.ts, apps/cli/src/prompts/addons.ts, apps/cli/test/generated-builds/samples.ts
The addon schema accepts mockatoo. Compatibility validation requires Better Auth and rejects Convex. The CLI lists Mockatoo in “Development & Testing,” and the generated-build samples include a Mockatoo configuration.
Generated dependency and environment setup
packages/template-generator/src/utils/add-deps.ts, packages/template-generator/src/processors/auth-deps.ts, packages/template-generator/src/processors/env-vars.ts, packages/template-generator/src/processors/varlock.ts
When Mockatoo is enabled, the generated project includes the Better Auth connector dependency and GitHub client environment variables. Varlock marks both credentials as required in production and marks the client ID as non-sensitive.
Better Auth and sign-in flow
packages/template-generator/templates/auth/better-auth/server/base/src/index.ts.hbs, packages/template-generator/templates/auth/better-auth/web/react/next/src/components/sign-in-form.tsx.hbs
When Mockatoo is enabled, the generated server configures GitHub as a social provider in production and includes the Mockatoo plugin outside production. The sign-in form displays a GitHub button that starts social sign-in with a /dashboard callback URL.
Merge Risk: Moderate · previous review 1b8e4

Generated apps use the mock GitHub login whenever NODE_ENV is not exactly "production", so a deployment without that variable would not use the real GitHub login. Adding Mockatoo to an existing project reports success without changing anything. Fix the environment gating and the add-flow behavior before merging. The missing error message on the sign-in button is a minor follow-up.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(cli): opt-in Mockatoo GitHub sign-in addon for dev and tests" matches the main change. The PR adds an opt-in mockatoo addon to the CLI. The addon gives a GitHub sign-in button that u…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "feat(cli): opt-in Mockatoo GitHub sign-in addon for dev and tests" matches the main change. The PR adds an opt-in mockatoo addon to the CLI. The addon gives a GitHub sign-in button that uses Mockatoo in development and tests. The changeset covers the CLI addon registry, compatibility rules, schemas, template generation, env vars, and the Better Auth templates, which all support this addon. The title is specific and concise, and it fits the changes described in the summary.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6d9dbc7d-7a67-40de-af36-2c08004a4edc
Commits

Reviewing files that changed from the base of the PR and between a9bd456 and 1b8e4bd.

Files ignored due to path filters: 1

  • packages/template-generator/src/templates.generated.ts is excluded by !**/*.generated.*
Files selected for processing: 10

  • apps/cli/src/prompts/addons.ts
  • apps/cli/test/generated-builds/samples.ts
  • packages/template-generator/src/processors/auth-deps.ts
  • packages/template-generator/src/processors/env-vars.ts
  • packages/template-generator/src/processors/varlock.ts
  • packages/template-generator/src/utils/add-deps.ts
  • packages/template-generator/templates/auth/better-auth/server/base/src/index.ts.hbs
  • packages/template-generator/templates/auth/better-auth/web/react/next/src/components/sign-in-form.tsx.hbs
  • packages/types/src/compatibility.ts
  • packages/types/src/schemas.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

"Code Quality": ["biome", "oxlint", "ultracite", "husky", "lefthook"],
Documentation: ["starlight", "fumadocs"],
"Platform Extensions": ["pwa", "tauri", "electrobun", "opentui", "wxt"],
"Development & Testing": ["mockatoo"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Major · Functional Correctness · Heavy lift

Mockatoo add flow for existing projects writes no changes.

Selecting mockatoo for an existing project does not add its files, dependency, env keys, or sign-in button. addHandler still records the addon and reports success. The Mockatoo branches are in creation-only processors (processAuthDeps, the env processors, and base templates). processAddonsDeps and processAddonTemplates have no matching output. Users can therefore see "Added mockatoo" without GitHub sign-in being enabled.

Either implement the existing-project path, or reject mockatoo in the add command before the addon is recorded. The implementation path must update the auth server, the sign-in form, the env schema, and the dependency set. The rejection path must keep mockatoo unavailable to existing-project adds.

{{/if}}
plugins: [
{{#if (includes addons "mockatoo")}}
...(process.env.NODE_ENV === "production" ? [] : [mockGitHub(github)]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Major · Security & Privacy · Quick win

Enable mock authentication only in development and tests.

If NODE_ENV is unset or has an unexpected value in a deployed server, this branch enables mockGitHub. Line 69 also disables the real GitHub provider. Production therefore depends on an exact environment value to exclude mock authentication.

Use an explicit allowlist for "development" and "test" in both branches. Default all other values to the real provider.

Based on learnings, development-only behavior must default to production-safe behavior when the environment is unset or misconfigured.

Source: Learnings

type="button"
variant="outline"
className="mt-4 w-full"
onClick={() => authClient.signIn.social({ provider: "github", callbackURL: `${window.location.origin}/dashboard` })}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Show an error when GitHub sign-in fails to start.

The GitHub button discards the result of authClient.signIn.social. If the request returns an error, the user can remain on the form with no message. The email sign-in path reports the same kind of failure with toast.error.

Suggested fix

--- "a/packages/template-generator/templates/auth/better-auth/web/react/next/src/components/sign-in-form.tsx.hbs"
+++ "b/packages/template-generator/templates/auth/better-auth/web/react/next/src/components/sign-in-form.tsx.hbs"
@@ -126,7 +126,11 @@
         type="button"
         variant="outline"
         className="mt-4 w-full"
-        onClick={() => authClient.signIn.social({ provider: "github", callbackURL: `${window.location.origin}/dashboard` })}
+        onClick={() => authClient.signIn.social({ provider: "github", callbackURL: `${window.location.origin}/dashboard` }, {
+          onError: (error) => {
+            toast.error(error.error.message || error.error.statusText);
+          },
+        })}
       >
         Continue with GitHub
       </Button>
Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
onClick={() => authClient.signIn.social({ provider: "github", callbackURL: `${window.location.origin}/dashboard` })}
onClick={() => authClient.signIn.social({ provider: "github", callbackURL: `${window.location.origin}/dashboard` }, {
onError: (error) => {
toast.error(error.error.message || error.error.statusText);
},
})}

This branch has not been deployed

No deployments
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.

1 participant