create-better-t-stack 3.9.0 → 3.11.0-pr749.5d055e3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +2 -1
  2. package/bin/create-better-t-stack +98 -0
  3. package/package.json +51 -55
  4. package/scripts/postinstall.mjs +129 -0
  5. package/templates/auth/better-auth/convex/backend/convex/auth.config.ts.hbs +5 -7
  6. package/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs +17 -17
  7. package/templates/auth/better-auth/convex/backend/convex/http.ts.hbs +4 -4
  8. package/templates/auth/better-auth/convex/web/react/next/src/app/api/auth/[...all]/route.ts.hbs +2 -2
  9. package/templates/auth/better-auth/convex/web/react/next/src/components/user-menu.tsx.hbs +10 -10
  10. package/templates/auth/better-auth/convex/web/react/next/src/lib/auth-server.ts.hbs +13 -5
  11. package/templates/auth/better-auth/convex/web/react/tanstack-router/src/components/user-menu.tsx.hbs +14 -12
  12. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/components/user-menu.tsx.hbs +13 -16
  13. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/lib/auth-server.ts.hbs +11 -5
  14. package/templates/auth/better-auth/convex/web/react/tanstack-start/src/routes/api/auth/$.ts.hbs +4 -4
  15. package/templates/auth/better-auth/fullstack/tanstack-start/src/routes/api/auth/$.ts.hbs +1 -1
  16. package/templates/auth/better-auth/web/react/next/src/components/user-menu.tsx.hbs +17 -15
  17. package/templates/auth/better-auth/web/react/react-router/src/components/user-menu.tsx.hbs +16 -15
  18. package/templates/auth/better-auth/web/react/tanstack-router/src/components/{user-menu.tsx → user-menu.tsx.hbs} +16 -15
  19. package/templates/auth/better-auth/web/react/tanstack-start/src/components/{user-menu.tsx → user-menu.tsx.hbs} +16 -15
  20. package/templates/backend/convex/packages/backend/convex/README.md +4 -4
  21. package/templates/backend/convex/packages/backend/convex/convex.config.ts.hbs +17 -0
  22. package/templates/backend/convex/packages/backend/convex/tsconfig.json.hbs +1 -1
  23. package/templates/examples/ai/convex/packages/backend/convex/agent.ts.hbs +9 -0
  24. package/templates/examples/ai/convex/packages/backend/convex/chat.ts.hbs +67 -0
  25. package/templates/examples/ai/native/bare/app/(drawer)/ai.tsx.hbs +301 -3
  26. package/templates/examples/ai/native/unistyles/app/(drawer)/ai.tsx.hbs +296 -10
  27. package/templates/examples/ai/native/uniwind/app/(drawer)/ai.tsx.hbs +180 -1
  28. package/templates/examples/ai/web/react/next/src/app/ai/page.tsx.hbs +172 -9
  29. package/templates/examples/ai/web/react/react-router/src/routes/ai.tsx.hbs +156 -6
  30. package/templates/examples/ai/web/react/tanstack-router/src/routes/ai.tsx.hbs +156 -4
  31. package/templates/examples/ai/web/react/tanstack-start/src/routes/ai.tsx.hbs +159 -6
  32. package/templates/frontend/react/next/package.json.hbs +8 -7
  33. package/templates/frontend/react/next/src/app/layout.tsx.hbs +28 -1
  34. package/templates/frontend/react/next/src/components/mode-toggle.tsx.hbs +4 -6
  35. package/templates/frontend/react/next/src/components/providers.tsx.hbs +14 -4
  36. package/templates/frontend/react/react-router/package.json.hbs +2 -1
  37. package/templates/frontend/react/{tanstack-router/src/components/mode-toggle.tsx → react-router/src/components/mode-toggle.tsx.hbs} +4 -6
  38. package/templates/frontend/react/tanstack-router/package.json.hbs +2 -1
  39. package/templates/frontend/react/{react-router/src/components/mode-toggle.tsx → tanstack-router/src/components/mode-toggle.tsx.hbs} +4 -6
  40. package/templates/frontend/react/tanstack-start/package.json.hbs +2 -1
  41. package/templates/frontend/react/tanstack-start/src/router.tsx.hbs +6 -0
  42. package/templates/frontend/react/tanstack-start/src/routes/__root.tsx.hbs +13 -14
  43. package/templates/frontend/react/tanstack-start/vite.config.ts.hbs +5 -0
  44. package/templates/frontend/react/web-base/components.json +5 -2
  45. package/templates/frontend/react/web-base/src/components/ui/button.tsx.hbs +57 -0
  46. package/templates/frontend/react/web-base/src/components/ui/card.tsx.hbs +103 -0
  47. package/templates/frontend/react/web-base/src/components/ui/checkbox.tsx.hbs +26 -0
  48. package/templates/frontend/react/web-base/src/components/ui/dropdown-menu.tsx.hbs +262 -0
  49. package/templates/frontend/react/web-base/src/components/ui/input.tsx.hbs +20 -0
  50. package/templates/frontend/react/web-base/src/components/ui/label.tsx.hbs +20 -0
  51. package/templates/frontend/react/web-base/src/components/ui/skeleton.tsx.hbs +13 -0
  52. package/templates/frontend/react/web-base/src/components/ui/sonner.tsx.hbs +44 -0
  53. package/templates/frontend/react/web-base/src/index.css.hbs +58 -64
  54. package/dist/cli.d.mts +0 -1
  55. package/dist/cli.mjs +0 -8
  56. package/dist/index.d.mts +0 -347
  57. package/dist/index.mjs +0 -4
  58. package/dist/src-DLvUK0Qf.mjs +0 -7069
  59. package/templates/auth/better-auth/convex/backend/convex/convex.config.ts.hbs +0 -7
  60. package/templates/examples/ai/web/react/base/src/components/response.tsx.hbs +0 -22
  61. package/templates/frontend/react/web-base/src/components/ui/button.tsx +0 -56
  62. package/templates/frontend/react/web-base/src/components/ui/card.tsx +0 -75
  63. package/templates/frontend/react/web-base/src/components/ui/checkbox.tsx +0 -27
  64. package/templates/frontend/react/web-base/src/components/ui/dropdown-menu.tsx +0 -228
  65. package/templates/frontend/react/web-base/src/components/ui/input.tsx +0 -21
  66. package/templates/frontend/react/web-base/src/components/ui/label.tsx +0 -19
  67. package/templates/frontend/react/web-base/src/components/ui/skeleton.tsx +0 -13
  68. package/templates/frontend/react/web-base/src/components/ui/sonner.tsx +0 -25
  69. /package/templates/auth/better-auth/web/react/tanstack-router/src/components/{sign-in-form.tsx → sign-in-form.tsx.hbs} +0 -0
  70. /package/templates/auth/better-auth/web/react/tanstack-router/src/components/{sign-up-form.tsx → sign-up-form.tsx.hbs} +0 -0
  71. /package/templates/auth/better-auth/web/react/tanstack-router/src/routes/{login.tsx → login.tsx.hbs} +0 -0
  72. /package/templates/auth/better-auth/web/react/tanstack-start/src/components/{sign-in-form.tsx → sign-in-form.tsx.hbs} +0 -0
  73. /package/templates/auth/better-auth/web/react/tanstack-start/src/components/{sign-up-form.tsx → sign-up-form.tsx.hbs} +0 -0
  74. /package/templates/auth/better-auth/web/react/tanstack-start/src/routes/{login.tsx → login.tsx.hbs} +0 -0
  75. /package/templates/auth/better-auth/web/solid/src/components/{sign-in-form.tsx → sign-in-form.tsx.hbs} +0 -0
  76. /package/templates/auth/better-auth/web/solid/src/components/{sign-up-form.tsx → sign-up-form.tsx.hbs} +0 -0
  77. /package/templates/auth/better-auth/web/solid/src/routes/{login.tsx → login.tsx.hbs} +0 -0
  78. /package/templates/frontend/react/react-router/src/components/{theme-provider.tsx → theme-provider.tsx.hbs} +0 -0
  79. /package/templates/frontend/react/tanstack-router/src/components/{theme-provider.tsx → theme-provider.tsx.hbs} +0 -0
  80. /package/templates/frontend/react/web-base/src/lib/{utils.ts → utils.ts.hbs} +0 -0
package/README.md CHANGED
@@ -38,7 +38,7 @@ Follow the prompts to configure your project or use the `--yes` flag for default
38
38
  | **Runtime** | • Bun<br>• Node.js<br>• Cloudflare Workers<br>• None |
39
39
  | **Database** | • SQLite<br>• PostgreSQL<br>• MySQL<br>• MongoDB<br>• None |
40
40
  | **ORM** | • Drizzle (TypeScript-first)<br>• Prisma (feature-rich)<br>• Mongoose (for MongoDB)<br>• None |
41
- | **Database Setup** | • Turso (SQLite)<br>• Cloudflare D1 (SQLite)<br>• Neon (PostgreSQL)<br>• Supabase (PostgreSQL)<br>• Prisma Postgres<br>• MongoDB Atlas<br>• None (manual setup) |
41
+ | **Database Setup** | • Turso (SQLite)<br>• Cloudflare D1 (SQLite)<br>• Neon (PostgreSQL)<br>• Supabase (PostgreSQL)<br>• Prisma Postgres<br>• MongoDB Atlas<br>• None (manual setup) |
42
42
  | **Authentication** | Better-Auth (email/password, with more options coming soon) |
43
43
  | **Styling** | Tailwind CSS with shadcn/ui components |
44
44
  | **Addons** | • PWA support<br>• Tauri (desktop applications)<br>• Starlight (documentation site)<br>• Biome (linting and formatting)<br>• Husky (Git hooks)<br>• Turborepo (optimized builds) |
@@ -77,6 +77,7 @@ Options:
77
77
  ## Telemetry
78
78
 
79
79
  This CLI collects anonymous usage data to help improve the tool. The data collected includes:
80
+
80
81
  - Configuration options selected
81
82
  - CLI version
82
83
  - Node.js version
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Bin stub for create-better-t-stack.
5
+ * Finds and runs the platform-specific compiled binary.
6
+ *
7
+ * The binary is installed as an optional dependency:
8
+ * @better-t-stack/cli-{platform}-{arch}
9
+ *
10
+ * This stub searches node_modules for the matching binary package.
11
+ */
12
+
13
+ import { spawnSync } from "node:child_process";
14
+ import { existsSync, realpathSync } from "node:fs";
15
+ import { dirname, join } from "node:path";
16
+ import { platform as osPlatform, arch as osArch } from "node:os";
17
+ import { fileURLToPath } from "node:url";
18
+
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = dirname(__filename);
21
+
22
+ function run(target) {
23
+ const result = spawnSync(target, process.argv.slice(2), {
24
+ stdio: "inherit",
25
+ });
26
+ if (result.error) {
27
+ console.error(result.error.message);
28
+ process.exit(1);
29
+ }
30
+ const code = typeof result.status === "number" ? result.status : 0;
31
+ process.exit(code);
32
+ }
33
+
34
+ // Allow override via environment variable
35
+ const envPath = process.env.CREATE_BETTER_T_STACK_BIN_PATH;
36
+ if (envPath) {
37
+ run(envPath);
38
+ }
39
+
40
+ const scriptPath = realpathSync(__filename);
41
+ const scriptDir = dirname(scriptPath);
42
+
43
+ const platformMap = {
44
+ darwin: "darwin",
45
+ linux: "linux",
46
+ win32: "windows",
47
+ };
48
+
49
+ const archMap = {
50
+ x64: "x64",
51
+ arm64: "arm64",
52
+ };
53
+
54
+ let platform = platformMap[osPlatform()];
55
+ if (!platform) {
56
+ platform = osPlatform();
57
+ }
58
+
59
+ let arch = archMap[osArch()];
60
+ if (!arch) {
61
+ arch = osArch();
62
+ }
63
+
64
+ // Scoped package name: @better-t-stack/cli-{platform}-{arch}
65
+ const scopedPackage = "@better-t-stack/cli-" + platform + "-" + arch;
66
+ const binary = platform === "windows" ? "create-better-t-stack.exe" : "create-better-t-stack";
67
+
68
+ function findBinary(startDir) {
69
+ let current = startDir;
70
+ for (; ;) {
71
+ const modules = join(current, "node_modules");
72
+ if (existsSync(modules)) {
73
+ // Check for scoped package: node_modules/@better-t-stack/cli-{platform}-{arch}
74
+ const scopedPath = join(modules, "@better-t-stack", "cli-" + platform + "-" + arch);
75
+ const candidate = join(scopedPath, "bin", binary);
76
+ if (existsSync(candidate)) {
77
+ return candidate;
78
+ }
79
+ }
80
+ const parent = dirname(current);
81
+ if (parent === current) {
82
+ return;
83
+ }
84
+ current = parent;
85
+ }
86
+ }
87
+
88
+ const resolved = findBinary(scriptDir);
89
+
90
+ if (!resolved) {
91
+ console.error(
92
+ 'No binary found for your platform (' + platform + '-' + arch + ').\n' +
93
+ 'You can try manually installing the "' + scopedPackage + '" package.',
94
+ );
95
+ process.exit(1);
96
+ }
97
+
98
+ run(resolved);
package/package.json CHANGED
@@ -1,95 +1,91 @@
1
1
  {
2
2
  "name": "create-better-t-stack",
3
- "version": "3.9.0",
3
+ "version": "3.11.0-pr749.5d055e3",
4
4
  "description": "A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations",
5
- "type": "module",
6
- "license": "MIT",
7
- "author": "Aman Varshney",
8
- "bin": {
9
- "create-better-t-stack": "dist/cli.mjs"
10
- },
11
- "files": [
12
- "templates",
13
- "dist"
14
- ],
15
5
  "keywords": [
6
+ "better-auth",
16
7
  "better-t-stack",
17
- "typescript",
8
+ "biome",
18
9
  "boilerplate",
19
- "starter",
20
10
  "cli",
21
- "turborepo",
22
- "trpc",
23
- "better-auth",
24
- "monorepo",
25
- "fullstack",
26
- "type-safety",
27
- "react",
28
- "react-native",
11
+ "drizzle",
12
+ "elysia",
29
13
  "expo",
14
+ "fullstack",
30
15
  "hono",
31
- "elysia",
32
- "drizzle",
16
+ "monorepo",
33
17
  "prisma",
34
- "tanstack",
35
- "tailwind",
36
- "shadcn",
37
18
  "pwa",
19
+ "react",
20
+ "react-native",
21
+ "shadcn",
22
+ "starter",
23
+ "tailwind",
24
+ "tanstack",
38
25
  "tauri",
39
- "biome"
26
+ "trpc",
27
+ "turborepo",
28
+ "type-safety",
29
+ "typescript"
40
30
  ],
31
+ "homepage": "https://better-t-stack.dev/",
32
+ "license": "MIT",
33
+ "author": "Aman Varshney",
41
34
  "repository": {
42
35
  "type": "git",
43
36
  "url": "git+https://github.com/AmanVarshney01/create-better-t-stack.git",
44
37
  "directory": "apps/cli"
45
38
  },
39
+ "bin": {
40
+ "create-better-t-stack": "./bin/create-better-t-stack"
41
+ },
42
+ "files": [
43
+ "bin",
44
+ "templates",
45
+ "scripts/postinstall.mjs"
46
+ ],
47
+ "type": "module",
46
48
  "publishConfig": {
47
49
  "access": "public"
48
50
  },
49
- "homepage": "https://better-t-stack.dev/",
50
51
  "scripts": {
51
- "build": "tsdown --publint",
52
- "dev": "tsdown --watch",
52
+ "build": "bun run scripts/build.ts",
53
+ "build:local": "bun run scripts/build.ts --single",
54
+ "dev": "bun run src/cli.ts",
53
55
  "check-types": "tsc --noEmit",
54
- "test": "bun run build && bun test",
55
- "test:watch": "bun run build && bun test --watch",
56
- "test:coverage": "bun run build && bun test --coverage",
57
- "test:ci": "bun run build && AGENT=1 bun test --bail=5",
58
- "prepublishOnly": "npm run build"
59
- },
60
- "exports": {
61
- ".": {
62
- "types": "./dist/index.d.mts",
63
- "import": "./dist/index.mjs"
64
- },
65
- "./cli": {
66
- "import": "./dist/cli.mjs"
67
- }
56
+ "test": "bun test",
57
+ "test:watch": "bun test --watch",
58
+ "test:coverage": "bun test --coverage",
59
+ "test:ci": "AGENT=1 bun test --bail=5",
60
+ "prepublishOnly": "echo 'Build binaries separately before publishing'",
61
+ "postinstall": "node ./scripts/postinstall.mjs || true"
68
62
  },
69
63
  "dependencies": {
70
- "@better-t-stack/types": "^3.9.0",
64
+ "@better-t-stack/types": "3.11.0-pr749.5d055e3",
71
65
  "@clack/prompts": "^1.0.0-alpha.8",
72
- "@orpc/server": "^1.12.2",
66
+ "commander": "^14.0.2",
73
67
  "consola": "^3.4.2",
74
- "execa": "^9.6.1",
75
- "fs-extra": "^11.3.2",
68
+ "fs-extra": "^11.3.3",
76
69
  "gradient-string": "^3.0.0",
77
70
  "handlebars": "^4.7.8",
78
71
  "jsonc-parser": "^3.3.1",
79
- "oxfmt": "^0.19.0",
80
72
  "picocolors": "^1.1.1",
81
73
  "tinyglobby": "^0.2.15",
82
- "trpc-cli": "^0.12.1",
83
74
  "ts-morph": "^27.0.2",
84
75
  "yaml": "^2.8.2",
85
- "zod": "^4.1.13"
76
+ "zod": "^4.2.1"
86
77
  },
87
78
  "devDependencies": {
88
- "@types/bun": "^1.2.17",
79
+ "@types/bun": "^1.3.5",
89
80
  "@types/fs-extra": "^11.0.4",
90
- "@types/node": "^24.10.2",
91
- "publint": "^0.3.16",
92
- "tsdown": "^0.17.2",
81
+ "@types/node": "^25.0.3",
93
82
  "typescript": "^5.9.3"
83
+ },
84
+ "optionalDependencies": {
85
+ "@better-t-stack/cli-darwin-arm64": "3.11.0",
86
+ "@better-t-stack/cli-darwin-x64": "3.11.0",
87
+ "@better-t-stack/cli-linux-arm64": "3.11.0",
88
+ "@better-t-stack/cli-linux-x64": "3.11.0",
89
+ "@better-t-stack/cli-windows-x64": "3.11.0"
94
90
  }
95
91
  }
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Postinstall script for create-better-t-stack.
5
+ * Symlinks the platform-specific binary to the bin directory for convenience.
6
+ *
7
+ * This runs after npm install to set up the binary.
8
+ */
9
+
10
+ import fs from "fs";
11
+ import path from "path";
12
+ import os from "os";
13
+ import { fileURLToPath } from "url";
14
+ import { createRequire } from "module";
15
+
16
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
17
+ const require = createRequire(import.meta.url);
18
+
19
+ function detectPlatformAndArch() {
20
+ let platform;
21
+ switch (os.platform()) {
22
+ case "darwin":
23
+ platform = "darwin";
24
+ break;
25
+ case "linux":
26
+ platform = "linux";
27
+ break;
28
+ case "win32":
29
+ platform = "windows";
30
+ break;
31
+ default:
32
+ platform = os.platform();
33
+ break;
34
+ }
35
+
36
+ let arch;
37
+ switch (os.arch()) {
38
+ case "x64":
39
+ arch = "x64";
40
+ break;
41
+ case "arm64":
42
+ arch = "arm64";
43
+ break;
44
+ default:
45
+ arch = os.arch();
46
+ break;
47
+ }
48
+
49
+ return { platform, arch };
50
+ }
51
+
52
+ function findBinary() {
53
+ const { platform, arch } = detectPlatformAndArch();
54
+ // Scoped package: @better-t-stack/cli-{platform}-{arch}
55
+ const packageName = `@better-t-stack/cli-${platform}-${arch}`;
56
+ const binaryName = platform === "windows" ? "create-better-t-stack.exe" : "create-better-t-stack";
57
+
58
+ try {
59
+ // Use require.resolve to find the package
60
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
61
+ const packageDir = path.dirname(packageJsonPath);
62
+ const binaryPath = path.join(packageDir, "bin", binaryName);
63
+
64
+ if (!fs.existsSync(binaryPath)) {
65
+ throw new Error(`Binary not found at ${binaryPath}`);
66
+ }
67
+
68
+ return { binaryPath, binaryName };
69
+ } catch (error) {
70
+ throw new Error(`Could not find package ${packageName}: ${error.message}`);
71
+ }
72
+ }
73
+
74
+ function prepareBinDirectory(binaryName) {
75
+ const binDir = path.join(__dirname, "..", "bin");
76
+ const targetPath = path.join(binDir, binaryName);
77
+
78
+ // Ensure bin directory exists
79
+ if (!fs.existsSync(binDir)) {
80
+ fs.mkdirSync(binDir, { recursive: true });
81
+ }
82
+
83
+ // Remove existing binary/symlink if it exists
84
+ try {
85
+ if (fs.existsSync(targetPath) || fs.lstatSync(targetPath).isSymbolicLink()) {
86
+ fs.unlinkSync(targetPath);
87
+ }
88
+ } catch {
89
+ // File doesn't exist, that's fine
90
+ }
91
+
92
+ return { binDir, targetPath };
93
+ }
94
+
95
+ function symlinkBinary(sourcePath, binaryName) {
96
+ const { targetPath } = prepareBinDirectory(binaryName);
97
+
98
+ fs.symlinkSync(sourcePath, targetPath);
99
+ console.log(`create-better-t-stack binary symlinked: ${targetPath} -> ${sourcePath}`);
100
+
101
+ // Verify the file exists after operation
102
+ if (!fs.existsSync(targetPath)) {
103
+ throw new Error(`Failed to symlink binary to ${targetPath}`);
104
+ }
105
+ }
106
+
107
+ async function main() {
108
+ try {
109
+ if (os.platform() === "win32") {
110
+ // On Windows, symlinks require admin privileges
111
+ // The bin stub will find the binary directly
112
+ console.log("Windows detected: skipping symlink (bin stub will find binary directly)");
113
+ return;
114
+ }
115
+
116
+ const { binaryPath, binaryName } = findBinary();
117
+ symlinkBinary(binaryPath, binaryName);
118
+ } catch (error) {
119
+ // Don't fail the install if we can't symlink - the bin stub will still work
120
+ console.log(`Note: Could not symlink binary (${error.message}). The CLI will still work.`);
121
+ }
122
+ }
123
+
124
+ try {
125
+ main();
126
+ } catch (error) {
127
+ // Silently continue - postinstall failures shouldn't break the install
128
+ console.log("Postinstall completed with warnings.");
129
+ }
@@ -1,8 +1,6 @@
1
+ import { getAuthConfigProvider } from "@convex-dev/better-auth/auth-config";
2
+ import type { AuthConfig } from "convex/server";
3
+
1
4
  export default {
2
- providers: [
3
- {
4
- domain: process.env.CONVEX_SITE_URL,
5
- applicationID: "convex",
6
- },
7
- ],
8
- };
5
+ providers: [getAuthConfigProvider()],
6
+ } satisfies AuthConfig;
@@ -2,19 +2,21 @@ import { createClient, type GenericCtx } from "@convex-dev/better-auth";
2
2
  {{#if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
3
3
  import { convex } from "@convex-dev/better-auth/plugins";
4
4
  import { expo } from "@better-auth/expo";
5
+ {{else if (or (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid"))}}
6
+ import { convex, crossDomain } from "@convex-dev/better-auth/plugins";
5
7
  {{else}}
6
8
  import { convex } from "@convex-dev/better-auth/plugins";
7
9
  {{/if}}
8
- {{#if (or (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid"))}}
9
- import { crossDomain } from "@convex-dev/better-auth/plugins";
10
- {{/if}}
11
10
  import { components } from "./_generated/api";
12
11
  import { DataModel } from "./_generated/dataModel";
13
12
  import { query } from "./_generated/server";
14
13
  import { betterAuth } from "better-auth";
15
14
  import { v } from "convex/values";
15
+ import authConfig from "./auth.config";
16
16
 
17
- {{#if (or (includes frontend "tanstack-start") (includes frontend "next") (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid"))}}
17
+ {{#if (or (includes frontend "tanstack-start") (includes frontend "next"))}}
18
+ const siteUrl = process.env.SITE_URL!;
19
+ {{else if (or (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid"))}}
18
20
  const siteUrl = process.env.SITE_URL!;
19
21
  {{/if}}
20
22
  {{#if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
@@ -23,23 +25,19 @@ const nativeAppUrl = process.env.NATIVE_APP_URL || "mybettertapp://";
23
25
 
24
26
  export const authComponent = createClient<DataModel>(components.betterAuth);
25
27
 
26
- function createAuth(
27
- ctx: GenericCtx<DataModel>,
28
- { optionsOnly }: { optionsOnly?: boolean } = { optionsOnly: false }
29
- ) {
28
+ function createAuth(ctx: GenericCtx<DataModel>) {
30
29
  return betterAuth({
31
- logger: {
32
- disabled: optionsOnly,
33
- },
34
30
  {{#if (and (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles")) (or (includes frontend "tanstack-start") (includes frontend "next")))}}
35
31
  baseURL: siteUrl,
36
32
  trustedOrigins: [siteUrl, nativeAppUrl],
33
+ {{else if (and (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles")) (or (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid")))}}
34
+ trustedOrigins: [siteUrl, nativeAppUrl],
37
35
  {{else if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
38
36
  trustedOrigins: [nativeAppUrl],
39
37
  {{else if (or (includes frontend "tanstack-start") (includes frontend "next"))}}
40
38
  baseURL: siteUrl,
41
39
  trustedOrigins: [siteUrl],
42
- {{else}}
40
+ {{else if (or (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid"))}}
43
41
  trustedOrigins: [siteUrl],
44
42
  {{/if}}
45
43
  database: authComponent.adapter(ctx),
@@ -50,11 +48,13 @@ function createAuth(
50
48
  plugins: [
51
49
  {{#if (or (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
52
50
  expo(),
53
- {{/if}}
54
- {{#if (or (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid"))}}
51
+ {{else if (or (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid"))}}
55
52
  crossDomain({ siteUrl }),
56
53
  {{/if}}
57
- convex(),
54
+ convex({
55
+ authConfig,
56
+ jwksRotateOnTokenGenerationError: true,
57
+ }),
58
58
  ],
59
59
  });
60
60
  }
@@ -64,7 +64,7 @@ export { createAuth };
64
64
  export const getCurrentUser = query({
65
65
  args: {},
66
66
  returns: v.any(),
67
- handler: async function (ctx, args) {
67
+ handler: async function (ctx) {
68
68
  return authComponent.getAuthUser(ctx);
69
69
  },
70
- });
70
+ });
@@ -3,10 +3,10 @@ import { authComponent, createAuth } from "./auth";
3
3
 
4
4
  const http = httpRouter();
5
5
 
6
- {{#if (or (includes frontend "tanstack-start") (includes frontend "next") (includes frontend "native-bare") (includes frontend "native-uniwind") (includes frontend "native-unistyles"))}}
7
- authComponent.registerRoutes(http, createAuth);
8
- {{else}}
6
+ {{#if (or (includes frontend "tanstack-router") (includes frontend "react-router") (includes frontend "nuxt") (includes frontend "svelte") (includes frontend "solid"))}}
9
7
  authComponent.registerRoutes(http, createAuth, { cors: true });
8
+ {{else}}
9
+ authComponent.registerRoutes(http, createAuth);
10
10
  {{/if}}
11
11
 
12
- export default http;
12
+ export default http;
@@ -1,3 +1,3 @@
1
- import { nextJsHandler } from "@convex-dev/better-auth/nextjs";
1
+ import { handler } from "@/lib/auth-server";
2
2
 
3
- export const { GET, POST } = nextJsHandler();
3
+ export const { GET, POST } = handler;
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  DropdownMenu,
3
3
  DropdownMenuContent,
4
+ DropdownMenuGroup,
4
5
  DropdownMenuItem,
5
6
  DropdownMenuLabel,
6
7
  DropdownMenuSeparator,
@@ -18,17 +19,16 @@ export default function UserMenu() {
18
19
 
19
20
  return (
20
21
  <DropdownMenu>
21
- <DropdownMenuTrigger asChild>
22
- <Button variant="outline">{user?.name}</Button>
22
+ <DropdownMenuTrigger render={<Button variant="outline" />}>
23
+ {user?.name}
23
24
  </DropdownMenuTrigger>
24
25
  <DropdownMenuContent className="bg-card">
25
- <DropdownMenuLabel>My Account</DropdownMenuLabel>
26
- <DropdownMenuSeparator />
27
- <DropdownMenuItem>{user?.email}</DropdownMenuItem>
28
- <DropdownMenuItem asChild>
29
- <Button
26
+ <DropdownMenuGroup>
27
+ <DropdownMenuLabel>My Account</DropdownMenuLabel>
28
+ <DropdownMenuSeparator />
29
+ <DropdownMenuItem>{user?.email}</DropdownMenuItem>
30
+ <DropdownMenuItem
30
31
  variant="destructive"
31
- className="w-full"
32
32
  onClick={() => {
33
33
  authClient.signOut({
34
34
  fetchOptions: {
@@ -40,8 +40,8 @@ export default function UserMenu() {
40
40
  }}
41
41
  >
42
42
  Sign Out
43
- </Button>
44
- </DropdownMenuItem>
43
+ </DropdownMenuItem>
44
+ </DropdownMenuGroup>
45
45
  </DropdownMenuContent>
46
46
  </DropdownMenu>
47
47
  );
@@ -1,6 +1,14 @@
1
- import { createAuth } from "@{{projectName}}/backend/convex/auth";
2
- import { getToken as getTokenNextjs } from "@convex-dev/better-auth/nextjs";
1
+ import { convexBetterAuthNextJs } from "@convex-dev/better-auth/nextjs";
3
2
 
4
- export const getToken = () => {
5
- return getTokenNextjs(createAuth);
6
- };
3
+ export const {
4
+ handler,
5
+ preloadAuthQuery,
6
+ isAuthenticated,
7
+ getToken,
8
+ fetchAuthQuery,
9
+ fetchAuthMutation,
10
+ fetchAuthAction,
11
+ } = convexBetterAuthNextJs({
12
+ convexUrl: process.env.NEXT_PUBLIC_CONVEX_URL!,
13
+ convexSiteUrl: process.env.NEXT_PUBLIC_CONVEX_SITE_URL!,
14
+ });
@@ -1,34 +1,36 @@
1
+ import { useNavigate } from "@tanstack/react-router";
2
+
1
3
  import {
2
4
  DropdownMenu,
3
5
  DropdownMenuContent,
6
+ DropdownMenuGroup,
4
7
  DropdownMenuItem,
5
8
  DropdownMenuLabel,
6
9
  DropdownMenuSeparator,
7
10
  DropdownMenuTrigger,
8
11
  } from "@/components/ui/dropdown-menu";
9
12
  import { authClient } from "@/lib/auth-client";
10
- import { useNavigate } from "@tanstack/react-router";
11
- import { Button } from "./ui/button";
12
13
  import { useQuery } from "convex/react";
13
14
  import { api } from "@{{projectName}}/backend/convex/_generated/api";
14
15
 
16
+ import { Button } from "./ui/button";
17
+
15
18
  export default function UserMenu() {
16
19
  const navigate = useNavigate();
17
20
  const user = useQuery(api.auth.getCurrentUser)
18
21
 
19
22
  return (
20
23
  <DropdownMenu>
21
- <DropdownMenuTrigger asChild>
22
- <Button variant="outline">{user?.name}</Button>
24
+ <DropdownMenuTrigger render={<Button variant="outline" />}>
25
+ {user?.name}
23
26
  </DropdownMenuTrigger>
24
27
  <DropdownMenuContent className="bg-card">
25
- <DropdownMenuLabel>My Account</DropdownMenuLabel>
26
- <DropdownMenuSeparator />
27
- <DropdownMenuItem>{user?.email}</DropdownMenuItem>
28
- <DropdownMenuItem asChild>
29
- <Button
28
+ <DropdownMenuGroup>
29
+ <DropdownMenuLabel>My Account</DropdownMenuLabel>
30
+ <DropdownMenuSeparator />
31
+ <DropdownMenuItem>{user?.email}</DropdownMenuItem>
32
+ <DropdownMenuItem
30
33
  variant="destructive"
31
- className="w-full"
32
34
  onClick={() => {
33
35
  authClient.signOut({
34
36
  fetchOptions: {
@@ -42,8 +44,8 @@ export default function UserMenu() {
42
44
  }}
43
45
  >
44
46
  Sign Out
45
- </Button>
46
- </DropdownMenuItem>
47
+ </DropdownMenuItem>
48
+ </DropdownMenuGroup>
47
49
  </DropdownMenuContent>
48
50
  </DropdownMenu>
49
51
  );