Skip to content

fix(cli): align Better Auth Mongo and Convex templates#1047

Merged
AmanVarshney01 merged 5 commits into
mainfrom
aman/update-better-auth-mongo-convex
May 21, 2026
Merged

fix(cli): align Better Auth Mongo and Convex templates#1047
AmanVarshney01 merged 5 commits into
mainfrom
aman/update-better-auth-mongo-convex

Conversation

@AmanVarshney01

@AmanVarshney01 AmanVarshney01 commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • update Better Auth, Convex Better Auth, Polar Better Auth, MongoDB, Mongoose, and Prisma dependency versions used by generated projects
  • align Convex Better Auth templates with the official React framework guide and keep the intentional Convex Better Auth Better Auth range comment
  • fix Mongoose Better Auth auth models to match the official Mongo adapter behavior with ObjectId ids and refs, timestamp defaults, and indexes
  • tighten Mongo/Mongoose todo scaffolds and add scaffold assertions for the auth wiring
  • add conditional pnpm allowBuilds for generated stacks that pull lifecycle-script dependencies, including React UI/shadcn, Cloudflare, PWA, Prisma, Node runtime, nx, and lefthook
  • ensure pnpm/bun extra config templates are emitted through the single-template path so pnpm-workspace.yaml exists even when catalogs do not create it later

Validation

  • cloned official Better Auth repo and generated Prisma/Drizzle schemas from its source CLI for comparison
  • cd packages/template-generator && bun run generate-templates
  • bun run build:cli
  • bun test apps/cli/test/auth.test.ts --test-name-pattern "better-auth \+ mongodb \+ mongoose|better-auth \+ convex backend|react-router with Convex Better Auth"
  • bun test apps/cli/test/pnpm-workspace.test.ts
  • bun run check
  • git diff --check
  • manual bunx pnpm@11.1.3 install smoke: TanStack Start + Convex + Better Auth + Cloudflare + Turborepo
  • manual bunx pnpm@11.1.3 install smoke: Prisma SQLite
  • manual bunx pnpm@11.1.3 install smoke: TanStack Router + PWA
  • manual bunx pnpm@11.1.3 install smoke: Node runtime + nx + lefthook

Summary by CodeRabbit

  • Tests

    • Expanded generation tests to verify MongoDB/Mongoose artifacts, Convex Better-Auth wiring, and workspace allowBuilds output.
  • Bug Fixes

    • Reordered auth client plugins and unified auth route registration to eager mode with CORS for affected frontends.
    • Todo APIs and schemas now produce/stringify stable IDs for MongoDB/Mongoose backends.
  • Refactor

    • Templates improved: MongoID handling, indexes, DB selection, Convex env/site-url guidance, and TypeScript types.
  • Chores

    • Bumped multiple dependency versions and streamlined extras/workspace template generation.

Review Change Stack

@vercel

vercel Bot commented May 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
create-better-t-stack-web Ready Ready Preview, Comment May 21, 2026 6:39am

Request Review

@AmanVarshney01 AmanVarshney01 marked this pull request as ready for review May 18, 2026 15:24
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Updates templates, processors, and tests to support Better-Auth with MongoDB/Mongoose and Convex: dependency bumps, Mongoose schema ObjectId/index changes, Convex env/wiring (CONVEX_SITE_URL, baseURL, eager registration, plugin order), todo ID stringification, pnpm workspace template, and expanded scaffold tests.

Changes

Better-Auth MongoDB + Convex + Todo Integration

Layer / File(s) Summary
Dependency version updates
packages/template-generator/src/utils/add-deps.ts
Bumped better-auth/@better-auth/expo, Prisma pins, mongoose to ^9.6.2, added mongodb@^7.2.0, and bumped @convex-dev/better-auth / @polar-sh/better-auth; adjusted CONVEX Better Auth semver pin.
Mongoose auth schema ObjectId redesign
packages/template-generator/src/templates.generated.ts, packages/template-generator/templates/auth/better-auth/server/db/mongoose/mongodb/src/models/auth.model.ts.hbs
User, session, account, and verification schemas now use ObjectId _id/userId, set _id auto-generation, require/default timestamps with Date.now, default emailVerified to false, and add indexes on userId/identifier.
Auth dependency processing and MongoDB client
packages/template-generator/src/processors/auth-deps.ts, packages/template-generator/src/processors/db-deps.ts, packages/template-generator/templates/db/mongoose/mongodb/src/index.ts.hbs, packages/template-generator/templates/backend/convex/packages/backend/convex/tsconfig.json.hbs
processAuthDeps now reads orm and conditionally includes mongodb for mongoose; Prisma MongoDB pinned to 6.19.3; Mongoose client uses db() (active connection DB); Convex tsconfig adds "types": ["node"].
Convex env generation and Better-Auth wiring
packages/template-generator/src/processors/env-vars.ts, packages/template-generator/src/templates.generated.ts, packages/template-generator/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs, packages/template-generator/templates/auth/better-auth/convex/backend/convex/http.ts.hbs, packages/template-generator/templates/auth/better-auth/convex/web/react/*/auth-client.ts.hbs
Add CONVEX_SITE_URL when frontend is react-router/tanstack-router; use it for baseURL in createAuth for those frontends; switch matching frontends to eager authComponent.registerRoutes(http, createAuth, { cors: true }); reorder authClient plugins to [convexClient(), crossDomainClient()].
Todo app MongoDB ID string conversion and client typing
packages/template-generator/src/templates.generated.ts, packages/template-generator/templates/examples/todo/server/mongoose/mongodb/src/models/todo.model.ts.hbs, packages/template-generator/templates/examples/todo/server/mongoose/base/src/routers/todo.ts.hbs, packages/template-generator/templates/examples/todo/web/react/*/routes/todos.tsx.hbs, packages/template-generator/templates/examples/todo/web/react/next/src/app/todos/page.tsx.hbs
Todo schema id becomes a required String defaulting to an ObjectId string; server routers stringify id in getAll/create; client routes/pages introduce conditional TodoId (string for mongoose/mongodb, number otherwise) and update handlers to accept it.
Extras & pnpm workspace
packages/template-generator/src/template-handlers/extras.ts, packages/template-generator/templates/extras/pnpm-workspace.yaml.hbs, packages/template-generator/templates/extras/pnpm-workspace.yaml
Switch extras processing to direct single-template generation, add pnpm-workspace.yaml.hbs with conditional allowBuilds, and remove the static workspace globs file entries.
Test assertions for generated output
apps/cli/test/auth.test.ts, apps/cli/test/pnpm-workspace.test.ts
Extend tests to assert result.projectDir exists, packages/auth/package.json pins mongodb to ^7.2.0, generated files include expected CONVEX_SITE_URL usage, eager route registration call, auth-client plugin ordering, ObjectId/index patterns, and pnpm allowBuilds behavior.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title concisely summarizes the main focus: aligning Better Auth templates for MongoDB and Convex backends. It is directly related to the primary changes across multiple template files and dependency configurations.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 256b8ad7-7e2e-4645-8af2-0c591f329ca3

📥 Commits

Reviewing files that changed from the base of the PR and between 5569d1c and ab75e92.

📒 Files selected for processing (18)
  • apps/cli/test/auth.test.ts
  • packages/template-generator/src/processors/auth-deps.ts
  • packages/template-generator/src/processors/db-deps.ts
  • packages/template-generator/src/templates.generated.ts
  • packages/template-generator/src/utils/add-deps.ts
  • packages/template-generator/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs
  • packages/template-generator/templates/auth/better-auth/convex/backend/convex/http.ts.hbs
  • packages/template-generator/templates/auth/better-auth/convex/web/react/react-router/src/lib/auth-client.ts.hbs
  • packages/template-generator/templates/auth/better-auth/convex/web/react/tanstack-router/src/lib/auth-client.ts.hbs
  • packages/template-generator/templates/auth/better-auth/server/db/mongoose/mongodb/src/models/auth.model.ts.hbs
  • packages/template-generator/templates/backend/convex/packages/backend/convex/tsconfig.json.hbs
  • packages/template-generator/templates/db/mongoose/mongodb/src/index.ts.hbs
  • packages/template-generator/templates/examples/todo/server/mongoose/base/src/routers/todo.ts.hbs
  • packages/template-generator/templates/examples/todo/server/mongoose/mongodb/src/models/todo.model.ts.hbs
  • packages/template-generator/templates/examples/todo/web/react/next/src/app/todos/page.tsx.hbs
  • packages/template-generator/templates/examples/todo/web/react/react-router/src/routes/todos.tsx.hbs
  • packages/template-generator/templates/examples/todo/web/react/tanstack-router/src/routes/todos.tsx.hbs
  • packages/template-generator/templates/examples/todo/web/react/tanstack-start/src/routes/todos.tsx.hbs
💤 Files with no reviewable changes (1)
  • packages/template-generator/templates/auth/better-auth/convex/backend/convex/http.ts.hbs

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bf9fb97c-4080-4f41-aff0-630be9dc9c62

📥 Commits

Reviewing files that changed from the base of the PR and between 7a51096 and b6be85e.

📒 Files selected for processing (19)
  • apps/cli/test/auth.test.ts
  • packages/template-generator/src/processors/auth-deps.ts
  • packages/template-generator/src/processors/db-deps.ts
  • packages/template-generator/src/processors/env-vars.ts
  • packages/template-generator/src/templates.generated.ts
  • packages/template-generator/src/utils/add-deps.ts
  • packages/template-generator/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs
  • packages/template-generator/templates/auth/better-auth/convex/backend/convex/http.ts.hbs
  • packages/template-generator/templates/auth/better-auth/convex/web/react/react-router/src/lib/auth-client.ts.hbs
  • packages/template-generator/templates/auth/better-auth/convex/web/react/tanstack-router/src/lib/auth-client.ts.hbs
  • packages/template-generator/templates/auth/better-auth/server/db/mongoose/mongodb/src/models/auth.model.ts.hbs
  • packages/template-generator/templates/backend/convex/packages/backend/convex/tsconfig.json.hbs
  • packages/template-generator/templates/db/mongoose/mongodb/src/index.ts.hbs
  • packages/template-generator/templates/examples/todo/server/mongoose/base/src/routers/todo.ts.hbs
  • packages/template-generator/templates/examples/todo/server/mongoose/mongodb/src/models/todo.model.ts.hbs
  • packages/template-generator/templates/examples/todo/web/react/next/src/app/todos/page.tsx.hbs
  • packages/template-generator/templates/examples/todo/web/react/react-router/src/routes/todos.tsx.hbs
  • packages/template-generator/templates/examples/todo/web/react/tanstack-router/src/routes/todos.tsx.hbs
  • packages/template-generator/templates/examples/todo/web/react/tanstack-start/src/routes/todos.tsx.hbs
💤 Files with no reviewable changes (1)
  • packages/template-generator/templates/auth/better-auth/convex/backend/convex/http.ts.hbs
✅ Files skipped from review due to trivial changes (2)
  • packages/template-generator/templates/auth/better-auth/convex/web/react/tanstack-router/src/lib/auth-client.ts.hbs
  • packages/template-generator/templates/auth/better-auth/convex/web/react/react-router/src/lib/auth-client.ts.hbs
🚧 Files skipped from review as they are similar to previous changes (13)
  • packages/template-generator/templates/examples/todo/web/react/tanstack-start/src/routes/todos.tsx.hbs
  • packages/template-generator/templates/backend/convex/packages/backend/convex/tsconfig.json.hbs
  • packages/template-generator/templates/examples/todo/server/mongoose/base/src/routers/todo.ts.hbs
  • packages/template-generator/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs
  • packages/template-generator/templates/examples/todo/server/mongoose/mongodb/src/models/todo.model.ts.hbs
  • packages/template-generator/templates/examples/todo/web/react/react-router/src/routes/todos.tsx.hbs
  • packages/template-generator/src/processors/db-deps.ts
  • packages/template-generator/src/utils/add-deps.ts
  • packages/template-generator/src/processors/env-vars.ts
  • apps/cli/test/auth.test.ts
  • packages/template-generator/src/processors/auth-deps.ts
  • packages/template-generator/templates/examples/todo/web/react/next/src/app/todos/page.tsx.hbs
  • packages/template-generator/templates/auth/better-auth/server/db/mongoose/mongodb/src/models/auth.model.ts.hbs

Comment thread packages/template-generator/src/templates.generated.ts Outdated

@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.

🧹 Nitpick comments (1)
apps/cli/test/pnpm-workspace.test.ts (1)

19-19: 💤 Low value

Consider defensive handling of projectDir.

The non-null assertion assumes expectSuccess guarantees projectDir is set. While this is likely intentional, a more defensive approach would make the contract explicit.

🛡️ Optional: Add explicit check
  expectSuccess(result);
+ if (!result.projectDir) {
+   throw new Error("Expected projectDir to be set after successful test run");
+ }

- const workspacePath = path.join(result.projectDir!, "pnpm-workspace.yaml");
+ const workspacePath = path.join(result.projectDir, "pnpm-workspace.yaml");

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 11f996c0-9f44-4eb7-ab6f-7e98b84abfff

📥 Commits

Reviewing files that changed from the base of the PR and between b6be85e and 8867df7.

📒 Files selected for processing (5)
  • apps/cli/test/pnpm-workspace.test.ts
  • packages/template-generator/src/template-handlers/extras.ts
  • packages/template-generator/src/templates.generated.ts
  • packages/template-generator/templates/extras/pnpm-workspace.yaml
  • packages/template-generator/templates/extras/pnpm-workspace.yaml.hbs
💤 Files with no reviewable changes (1)
  • packages/template-generator/templates/extras/pnpm-workspace.yaml

@AmanVarshney01 AmanVarshney01 merged commit 6ea25fa into main May 21, 2026
3 checks passed
@AmanVarshney01 AmanVarshney01 deleted the aman/update-better-auth-mongo-convex branch May 21, 2026 06:52
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