@clubedge/create-clubedge-app 0.3.0 → 0.5.0

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 (143) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +49 -13
  3. package/dist/cli/args.js +20 -0
  4. package/dist/cli/ui.js +6 -0
  5. package/dist/core/customize.js +167 -1
  6. package/dist/core/manifest.js +130 -3
  7. package/dist/core/plan.js +203 -3
  8. package/dist/index.js +91 -7
  9. package/dist/utils/fs.js +3 -0
  10. package/package.json +5 -4
  11. package/template/.dockerignore +3 -0
  12. package/template/.env.example +19 -6
  13. package/template/.github/workflows/ci.yml +34 -4
  14. package/template/.prettierignore +1 -0
  15. package/template/AGENTS.md +11 -3
  16. package/template/CONTRIBUTING.md +2 -2
  17. package/template/README.md +73 -54
  18. package/template/SETUP.md +112 -40
  19. package/template/_gitignore +6 -0
  20. package/template/apps/start/.env.example +40 -0
  21. package/template/apps/start/AGENTS.md +11 -0
  22. package/template/apps/start/Dockerfile +38 -0
  23. package/template/apps/start/components.json +21 -0
  24. package/template/apps/start/package.json +43 -0
  25. package/template/apps/start/public/.well-known/logo.svg +1 -0
  26. package/template/apps/start/public/favicon.ico +0 -0
  27. package/template/apps/start/src/components/auth/auth-form-controls.tsx +108 -0
  28. package/template/apps/start/src/components/branding/clubedge-mark.tsx +24 -0
  29. package/template/apps/start/src/components/dashboard/account-button.tsx +33 -0
  30. package/template/apps/start/src/components/dashboard/app-sidebar.tsx +90 -0
  31. package/template/apps/start/src/components/dashboard/variants/account-button.none.tsx +9 -0
  32. package/template/apps/start/src/components/landing/copy-command.tsx +46 -0
  33. package/template/apps/start/src/components/theme/theme-provider.tsx +41 -0
  34. package/template/apps/start/src/components/theme/theme-toggle.tsx +21 -0
  35. package/template/apps/start/src/config/site.json +11 -0
  36. package/template/apps/start/src/config/site.ts +20 -0
  37. package/template/apps/start/src/env/auth.test.ts +26 -0
  38. package/template/apps/start/src/env/auth.ts +46 -0
  39. package/template/apps/start/src/env/server.test.ts +32 -0
  40. package/template/apps/start/src/env/server.ts +43 -0
  41. package/template/apps/start/src/lib/login-url.test.ts +16 -0
  42. package/template/apps/start/src/lib/login-url.ts +16 -0
  43. package/template/apps/start/src/router.tsx +27 -0
  44. package/template/apps/start/src/routes/__root.tsx +59 -0
  45. package/template/apps/start/src/routes/api/health.ts +15 -0
  46. package/template/apps/start/src/routes/auth/callback.ts +10 -0
  47. package/template/apps/start/src/routes/auth/sign-in.ts +11 -0
  48. package/template/apps/start/src/routes/auth/sign-out.ts +11 -0
  49. package/template/apps/start/src/routes/auth/sign-up.ts +11 -0
  50. package/template/apps/start/src/routes/dashboard.tsx +361 -0
  51. package/template/apps/start/src/routes/index.tsx +237 -0
  52. package/template/apps/start/src/routes/login.tsx +164 -0
  53. package/template/apps/start/src/server/auth-forms.test.ts +169 -0
  54. package/template/apps/start/src/server/auth-forms.ts +118 -0
  55. package/template/apps/start/src/server/auth.functions.ts +27 -0
  56. package/template/apps/start/src/server/auth.ts +51 -0
  57. package/template/apps/start/src/server/cache.test.ts +65 -0
  58. package/template/apps/start/src/server/cache.ts +58 -0
  59. package/template/apps/start/src/server/cookies.test.ts +41 -0
  60. package/template/apps/start/src/server/cookies.ts +31 -0
  61. package/template/apps/start/src/server/db.ts +16 -0
  62. package/template/apps/start/src/server/storage.ts +42 -0
  63. package/template/apps/start/src/server/users.ts +17 -0
  64. package/template/apps/start/src/server/variants/auth.better-auth.ts +57 -0
  65. package/template/apps/start/src/server/variants/auth.functions.none.ts +9 -0
  66. package/template/apps/start/src/server/variants/auth.none.ts +28 -0
  67. package/template/apps/start/src/server/variants/cache.memory.ts +26 -0
  68. package/template/apps/start/src/server/variants/storage.supabase.ts +35 -0
  69. package/template/apps/start/src/start.ts +40 -0
  70. package/template/apps/start/src/styles.css +2 -0
  71. package/template/apps/start/tsconfig.json +19 -0
  72. package/template/apps/start/tsr.config.json +7 -0
  73. package/template/apps/start/vite.config.ts +27 -0
  74. package/template/apps/web/next.config.ts +9 -9
  75. package/template/apps/web/package.json +7 -2
  76. package/template/{scripts → apps/web/scripts}/start-standalone.mjs +1 -2
  77. package/template/apps/web/src/app/dashboard/_components/account-button.tsx +1 -1
  78. package/template/apps/web/src/app/dashboard/_components/app-sidebar.tsx +1 -1
  79. package/template/apps/web/src/app/dashboard/_components/variants/account-button.none.tsx +9 -0
  80. package/template/apps/web/src/app/dashboard/page.tsx +18 -8
  81. package/template/apps/web/src/app/login/page.tsx +5 -4
  82. package/template/apps/web/src/app/page.tsx +7 -3
  83. package/template/apps/web/src/env/auth.ts +48 -0
  84. package/template/apps/web/src/env/client.ts +1 -8
  85. package/template/apps/web/src/env/server.test.ts +27 -4
  86. package/template/apps/web/src/env/server.ts +19 -29
  87. package/template/apps/web/src/proxy.ts +5 -8
  88. package/template/apps/web/src/server/auth.ts +14 -26
  89. package/template/apps/web/src/server/cache.ts +36 -16
  90. package/template/apps/web/src/server/cookies.ts +18 -0
  91. package/template/apps/web/src/server/storage.ts +22 -19
  92. package/template/apps/web/src/server/variants/auth.better-auth.ts +63 -0
  93. package/template/apps/web/src/server/variants/auth.none.ts +26 -0
  94. package/template/apps/web/src/server/variants/cache.memory.ts +26 -0
  95. package/template/apps/web/src/server/variants/storage.supabase.ts +35 -0
  96. package/template/apps/web/src/variants/proxy.better-auth.ts +46 -0
  97. package/template/clubedge.template.json +173 -2
  98. package/template/e2e/app.ts +12 -0
  99. package/template/e2e/auth-flow.spec.ts +29 -0
  100. package/template/{apps/web/e2e → e2e}/auth.spec.ts +2 -12
  101. package/template/e2e/home.spec.ts +24 -0
  102. package/template/eslint.config.mjs +6 -1
  103. package/template/package.json +6 -6
  104. package/template/packages/auth/package.json +3 -6
  105. package/template/packages/auth-better-auth/drizzle/0000_initial.sql +50 -0
  106. package/template/packages/auth-better-auth/drizzle/meta/0000_snapshot.json +320 -0
  107. package/template/packages/auth-better-auth/drizzle/meta/_journal.json +13 -0
  108. package/template/packages/auth-better-auth/drizzle.config.ts +12 -0
  109. package/template/packages/auth-better-auth/package.json +31 -0
  110. package/template/packages/auth-better-auth/scripts/migrate.ts +14 -0
  111. package/template/packages/auth-better-auth/src/index.test.ts +118 -0
  112. package/template/packages/auth-better-auth/src/index.ts +135 -0
  113. package/template/packages/auth-better-auth/src/schema.ts +74 -0
  114. package/template/packages/auth-better-auth/tsconfig.json +4 -0
  115. package/template/packages/auth-supabase/package.json +24 -0
  116. package/template/packages/{auth/src/supabase.test.ts → auth-supabase/src/index.test.ts} +2 -2
  117. package/template/packages/{auth/src/supabase.ts → auth-supabase/src/index.ts} +1 -1
  118. package/template/packages/auth-supabase/tsconfig.json +4 -0
  119. package/template/packages/cache/package.json +1 -4
  120. package/template/packages/cache/src/index.ts +3 -13
  121. package/template/packages/cache/src/memory-cache.test.ts +40 -0
  122. package/template/packages/cache/src/memory-cache.ts +37 -0
  123. package/template/packages/cache-redis/package.json +22 -0
  124. package/template/packages/{cache → cache-redis}/src/index.test.ts +6 -15
  125. package/template/packages/{cache/src/redis.ts → cache-redis/src/index.ts} +2 -6
  126. package/template/packages/cache-redis/tsconfig.json +4 -0
  127. package/template/packages/core/package.json +1 -1
  128. package/template/packages/db/package.json +3 -2
  129. package/template/packages/storage/package.json +2 -9
  130. package/template/packages/storage-s3/package.json +23 -0
  131. package/template/packages/{storage/src/s3.test.ts → storage-s3/src/index.test.ts} +1 -1
  132. package/template/packages/{storage/src/s3.ts → storage-s3/src/index.ts} +1 -1
  133. package/template/packages/storage-s3/tsconfig.json +4 -0
  134. package/template/packages/storage-supabase/package.json +22 -0
  135. package/template/packages/{storage/src/supabase.ts → storage-supabase/src/index.ts} +1 -1
  136. package/template/packages/storage-supabase/tsconfig.json +4 -0
  137. package/template/packages/ui/package.json +1 -1
  138. package/template/playwright.config.ts +6 -2
  139. package/template/pnpm-lock.yaml +1912 -27
  140. package/template/turbo.json +1 -1
  141. package/template/vitest.config.ts +2 -0
  142. package/template.lock.json +96 -12
  143. package/template/apps/web/e2e/home.spec.ts +0 -15
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@clubedge/start",
3
+ "version": "0.5.0",
4
+ "private": true,
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "vite dev",
9
+ "build": "vite build",
10
+ "start": "node --env-file-if-exists=.env.local .output/server/index.mjs",
11
+ "typecheck": "tsr generate && tsc --noEmit"
12
+ },
13
+ "dependencies": {
14
+ "@clubedge/auth": "workspace:*",
15
+ "@clubedge/auth-better-auth": "workspace:*",
16
+ "@clubedge/auth-supabase": "workspace:*",
17
+ "@clubedge/cache": "workspace:*",
18
+ "@clubedge/cache-redis": "workspace:*",
19
+ "@clubedge/core": "workspace:*",
20
+ "@clubedge/db": "workspace:*",
21
+ "@clubedge/storage": "workspace:*",
22
+ "@clubedge/storage-s3": "workspace:*",
23
+ "@clubedge/storage-supabase": "workspace:*",
24
+ "@clubedge/ui": "workspace:*",
25
+ "@tanstack/react-router": "1.170.42",
26
+ "@tanstack/react-start": "1.168.61",
27
+ "lucide-react": "^0.468.0",
28
+ "react": "^19.2.0",
29
+ "react-dom": "^19.2.0",
30
+ "use-sync-external-store": "^1.7.0",
31
+ "zod": "^4.1.5"
32
+ },
33
+ "devDependencies": {
34
+ "@tailwindcss/vite": "^4.3.3",
35
+ "@tanstack/router-cli": "1.167.41",
36
+ "@types/react": "^19.1.13",
37
+ "@types/react-dom": "^19.1.9",
38
+ "@vitejs/plugin-react": "^6.1.2",
39
+ "nitro": "3.0.260903-beta",
40
+ "tailwindcss": "^4.1.13",
41
+ "vite": "^8.3.4"
42
+ }
43
+ }
@@ -0,0 +1 @@
1
+ <svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><defs><style>.cls-1{fill:#2563eb;}.cls-2,.cls-3{fill:#fff;}.cls-2{fill-rule:evenodd;}</style></defs><rect class="cls-1" width="512" height="512"/><path class="cls-2" d="M364.36,283a359.51,359.51,0,0,0-43.5-10.18,364.29,364.29,0,0,1,5.24-55.17l30-15.13,20.83,5.63v34.6A43.79,43.79,0,0,0,364.36,283Zm-66.88-13.4a395.53,395.53,0,0,0-82.94,0,390.43,390.43,0,0,0-3-39L256,253l44.45-22.42A390.43,390.43,0,0,0,297.48,269.6Zm-106.32,3.22c-39.75,6.75-76,19.56-106.55,36.9a175.47,175.47,0,0,1-2.52-29.64,173.14,173.14,0,0,1,31-99.15l72.81,36.72a364.29,364.29,0,0,1,5.24,55.17Zm230.41,60.63A174.34,174.34,0,0,1,352.17,425c-17.72-36.5-28.9-80.53-31-128.34,37.9,6.89,72.13,19.67,100.42,36.78Zm-89.78,103.2a174.19,174.19,0,0,1-151.57,0c20-40.75,32.48-90.09,34.24-143.46a373.23,373.23,0,0,1,83.1,0C299.32,346.56,311.75,395.9,331.79,436.65ZM159.85,425a174.36,174.36,0,0,1-69.41-91.56c28.3-17.11,62.53-29.89,100.42-36.78-2.11,47.81-13.3,91.84-31,128.34Z"/><path class="cls-2" d="M256,58l173,84.17-33.81,17.05L280.05,128.07c-6.92-4.44-16-6.2-24-6.2-7.37,0-15.32,1.45-21.88,4.94s-11.85,9.19-11.85,16.9,5.42,13.48,11.85,16.9,14.51,4.94,21.88,4.94a54.52,54.52,0,0,0,9.29-.78l77.41,20.93L256,229.42,83,142.17,256,58Z"/><path class="cls-2" d="M256,130.18c8.43,0,15.9,2.18,20.52,5.55l140,37.84v72.75a29.68,29.68,0,0,0-18.51,0V192l-132.36-35.8a45,45,0,0,1-9.6,1c-14,0-25.42-6.05-25.42-13.53S242,130.18,256,130.18Z"/><circle class="cls-3" cx="407.23" cy="274.28" r="22.68"/></svg>
@@ -0,0 +1,108 @@
1
+ import { ArrowRight, Eye, EyeOff, Loader2 } from "lucide-react";
2
+ import { createContext, useContext, useState, type ReactNode } from "react";
3
+
4
+ import { Button } from "@clubedge/ui/components/button";
5
+ import { Input } from "@clubedge/ui/components/input";
6
+ import { Label } from "@clubedge/ui/components/label";
7
+
8
+ // The form posts natively to a server route, so it works before hydration and without
9
+ // JavaScript. Once hydrated, the pending state disables repeat submissions.
10
+ const PendingContext = createContext(false);
11
+
12
+ export function AuthForm({ action, children }: { action: string; children: ReactNode }) {
13
+ const [pending, setPending] = useState(false);
14
+
15
+ return (
16
+ <form
17
+ action={action}
18
+ className="grid gap-5"
19
+ method="post"
20
+ onSubmit={(event) => {
21
+ if (pending) event.preventDefault();
22
+ else setPending(true);
23
+ }}
24
+ >
25
+ <PendingContext.Provider value={pending}>{children}</PendingContext.Provider>
26
+ </form>
27
+ );
28
+ }
29
+
30
+ export function PasswordField({ isSignUp }: { isSignUp: boolean }) {
31
+ const [visible, setVisible] = useState(false);
32
+ const pending = useContext(PendingContext);
33
+
34
+ return (
35
+ <div className="grid gap-2">
36
+ <Label htmlFor="password">Password</Label>
37
+ <div className="relative">
38
+ <Input
39
+ aria-describedby={isSignUp ? "password-hint" : undefined}
40
+ autoComplete={isSignUp ? "new-password" : "current-password"}
41
+ className="h-11 pr-11"
42
+ id="password"
43
+ maxLength={128}
44
+ minLength={8}
45
+ name="password"
46
+ placeholder={isSignUp ? "Create a password" : "Enter your password"}
47
+ // readOnly rather than disabled: disabled fields are left out of the submitted form.
48
+ readOnly={pending}
49
+ required
50
+ type={visible ? "text" : "password"}
51
+ />
52
+ <button
53
+ aria-label={visible ? "Hide password" : "Show password"}
54
+ aria-pressed={visible}
55
+ className="absolute inset-y-0 right-0 grid w-11 place-items-center rounded-r-md text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
56
+ onClick={() => setVisible((v) => !v)}
57
+ type="button"
58
+ >
59
+ {visible ? (
60
+ <EyeOff aria-hidden="true" className="size-4" />
61
+ ) : (
62
+ <Eye aria-hidden="true" className="size-4" />
63
+ )}
64
+ </button>
65
+ </div>
66
+ {isSignUp && (
67
+ <p className="text-xs text-muted-foreground" id="password-hint">
68
+ Use at least 8 characters.
69
+ </p>
70
+ )}
71
+ </div>
72
+ );
73
+ }
74
+
75
+ export function EmailField() {
76
+ const pending = useContext(PendingContext);
77
+
78
+ return (
79
+ <div className="grid gap-2">
80
+ <Label htmlFor="email">Email</Label>
81
+ <Input
82
+ autoComplete="email"
83
+ autoFocus
84
+ className="h-11"
85
+ id="email"
86
+ name="email"
87
+ placeholder="you@example.com"
88
+ readOnly={pending}
89
+ required
90
+ type="email"
91
+ />
92
+ </div>
93
+ );
94
+ }
95
+
96
+ export function SubmitButton({ children, disabled }: { children: ReactNode; disabled?: boolean }) {
97
+ const pending = useContext(PendingContext);
98
+
99
+ return (
100
+ <Button className="h-11 w-full justify-center" disabled={disabled || pending} type="submit">
101
+ {pending ? (
102
+ <Loader2 aria-hidden="true" className="animate-spin motion-reduce:animate-none" />
103
+ ) : null}
104
+ {children}
105
+ {!pending && <ArrowRight aria-hidden="true" />}
106
+ </Button>
107
+ );
108
+ }
@@ -0,0 +1,24 @@
1
+ type ClubedgeMarkProps = {
2
+ alt?: string;
3
+ className?: string;
4
+ priority?: boolean;
5
+ };
6
+
7
+ export function ClubedgeMark({
8
+ alt = "Clubedge",
9
+ className = "size-10",
10
+ priority = false,
11
+ }: ClubedgeMarkProps) {
12
+ return (
13
+ <img
14
+ alt={alt}
15
+ className={className}
16
+ decoding="async"
17
+ fetchPriority={priority ? "high" : "auto"}
18
+ height={512}
19
+ loading={priority ? "eager" : "lazy"}
20
+ src="/.well-known/logo.svg"
21
+ width={512}
22
+ />
23
+ );
24
+ }
@@ -0,0 +1,33 @@
1
+ import { Link } from "@tanstack/react-router";
2
+
3
+ import type { AuthUser } from "@/server/auth";
4
+ import { Button } from "@clubedge/ui/components/button";
5
+
6
+ type AccountButtonProps = {
7
+ user: AuthUser | null;
8
+ className?: string;
9
+ };
10
+
11
+ export function AccountButton({ user, className }: AccountButtonProps) {
12
+ if (!user) {
13
+ return (
14
+ <Button className={className} render={<Link to="/login" />} size="sm" variant="outline">
15
+ Sign in
16
+ </Button>
17
+ );
18
+ }
19
+
20
+ return (
21
+ <form action="/auth/sign-out" className={className} method="post">
22
+ <Button
23
+ className="w-full"
24
+ size="sm"
25
+ title={user.email ?? undefined}
26
+ type="submit"
27
+ variant="outline"
28
+ >
29
+ Sign out
30
+ </Button>
31
+ </form>
32
+ );
33
+ }
@@ -0,0 +1,90 @@
1
+ import { Activity, ArrowUpRight, Blocks, Github, LayoutDashboard } from "lucide-react";
2
+
3
+ import { ClubedgeMark } from "@/components/branding/clubedge-mark";
4
+ import { siteConfig } from "@/config/site";
5
+ import type { AuthUser } from "@/server/auth";
6
+ import {
7
+ Sidebar,
8
+ SidebarContent,
9
+ SidebarFooter,
10
+ SidebarGroup,
11
+ SidebarGroupLabel,
12
+ SidebarHeader,
13
+ SidebarMenu,
14
+ SidebarMenuButton,
15
+ SidebarMenuItem,
16
+ SidebarSeparator,
17
+ } from "@clubedge/ui/components/sidebar";
18
+
19
+ import { AccountButton } from "./account-button";
20
+
21
+ const navigation = [
22
+ { href: "#overview", label: "Overview", icon: LayoutDashboard },
23
+ { href: "#modules", label: "Modules", icon: Blocks },
24
+ { href: "#activity", label: "Setup status", icon: Activity },
25
+ ];
26
+
27
+ export function AppSidebar({ user }: { user: AuthUser | null }) {
28
+ return (
29
+ <Sidebar collapsible="icon" variant="inset">
30
+ <SidebarHeader>
31
+ <SidebarMenu>
32
+ <SidebarMenuItem>
33
+ <SidebarMenuButton
34
+ className="h-12"
35
+ render={<a href="#overview" aria-label={`${siteConfig.name} home`} />}
36
+ size="lg"
37
+ tooltip={siteConfig.name}
38
+ >
39
+ <ClubedgeMark alt="" className="size-8 shrink-0 rounded-lg" />
40
+ <span className="grid min-w-0 text-start leading-tight">
41
+ <span className="truncate font-semibold">{siteConfig.shortName}</span>
42
+ <span className="truncate text-xs text-sidebar-foreground/70">
43
+ {siteConfig.workspaceLabel}
44
+ </span>
45
+ </span>
46
+ </SidebarMenuButton>
47
+ </SidebarMenuItem>
48
+ </SidebarMenu>
49
+ </SidebarHeader>
50
+
51
+ <SidebarSeparator />
52
+
53
+ <SidebarContent>
54
+ <SidebarGroup>
55
+ <SidebarGroupLabel>Workspace</SidebarGroupLabel>
56
+ <SidebarMenu>
57
+ {navigation.map(({ href, label, icon: Icon }, index) => (
58
+ <SidebarMenuItem key={href}>
59
+ <SidebarMenuButton
60
+ render={<a href={href} aria-current={index === 0 ? "page" : undefined} />}
61
+ isActive={index === 0}
62
+ tooltip={label}
63
+ >
64
+ <Icon aria-hidden="true" />
65
+ <span>{label}</span>
66
+ </SidebarMenuButton>
67
+ </SidebarMenuItem>
68
+ ))}
69
+ </SidebarMenu>
70
+ </SidebarGroup>
71
+ </SidebarContent>
72
+
73
+ <SidebarFooter>
74
+ <SidebarMenu>
75
+ <SidebarMenuItem>
76
+ <SidebarMenuButton
77
+ render={<a href={siteConfig.links.repository} target="_blank" rel="noreferrer" />}
78
+ tooltip="Starter repository"
79
+ >
80
+ <Github aria-hidden="true" />
81
+ <span>Starter repository</span>
82
+ <ArrowUpRight aria-hidden="true" className="ms-auto" />
83
+ </SidebarMenuButton>
84
+ </SidebarMenuItem>
85
+ </SidebarMenu>
86
+ <AccountButton className="w-full" user={user} />
87
+ </SidebarFooter>
88
+ </Sidebar>
89
+ );
90
+ }
@@ -0,0 +1,9 @@
1
+ import type { AuthUser } from "@/server/auth";
2
+
3
+ type AccountButtonProps = {
4
+ user: AuthUser | null;
5
+ className?: string;
6
+ };
7
+
8
+ /** This project has no authentication, so there is no account to show. */
9
+ export const AccountButton: (props: AccountButtonProps) => null = () => null;
@@ -0,0 +1,46 @@
1
+ import { Check, Copy } from "lucide-react";
2
+ import { useEffect, useState } from "react";
3
+
4
+ export function CopyCommand({ command }: { command: string }) {
5
+ const [copied, setCopied] = useState(false);
6
+
7
+ useEffect(() => {
8
+ if (!copied) return;
9
+ const timer = setTimeout(() => setCopied(false), 2000);
10
+ return () => clearTimeout(timer);
11
+ }, [copied]);
12
+
13
+ async function handleCopy() {
14
+ try {
15
+ await navigator.clipboard.writeText(command);
16
+ setCopied(true);
17
+ } catch {
18
+ // Clipboard can be unavailable (insecure context, denied permission).
19
+ // The command stays selectable, so we fail silently.
20
+ }
21
+ }
22
+
23
+ return (
24
+ <div className="flex items-center gap-2 rounded-xl border bg-card py-2 pl-4 pr-2 shadow-sm">
25
+ <code className="min-w-0 flex-1 overflow-x-auto whitespace-nowrap py-1.5 font-mono text-sm text-foreground">
26
+ <span aria-hidden="true" className="select-none text-muted-foreground">
27
+ ${" "}
28
+ </span>
29
+ {command}
30
+ </code>
31
+ <button
32
+ aria-label={copied ? "Command copied" : "Copy command"}
33
+ className="inline-flex h-9 shrink-0 items-center gap-1.5 rounded-lg px-3 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
34
+ onClick={handleCopy}
35
+ type="button"
36
+ >
37
+ {copied ? (
38
+ <Check aria-hidden="true" className="size-4 text-primary" />
39
+ ) : (
40
+ <Copy aria-hidden="true" className="size-4" />
41
+ )}
42
+ <span aria-live="polite">{copied ? "Copied" : "Copy"}</span>
43
+ </button>
44
+ </div>
45
+ );
46
+ }
@@ -0,0 +1,41 @@
1
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
2
+
3
+ type Theme = "light" | "dark";
4
+
5
+ type ThemeContextValue = {
6
+ theme: Theme;
7
+ setTheme: (theme: Theme) => void;
8
+ };
9
+
10
+ const ThemeContext = createContext<ThemeContextValue | null>(null);
11
+
12
+ export function ThemeProvider({ children }: { children: React.ReactNode }) {
13
+ const [theme, setThemeState] = useState<Theme>("light");
14
+
15
+ useEffect(() => {
16
+ setThemeState(document.documentElement.classList.contains("dark") ? "dark" : "light");
17
+ }, []);
18
+
19
+ const setTheme = useCallback((nextTheme: Theme) => {
20
+ document.documentElement.classList.toggle("dark", nextTheme === "dark");
21
+ document.documentElement.style.colorScheme = nextTheme;
22
+ try {
23
+ window.localStorage.setItem("clubedge-theme", nextTheme);
24
+ } catch {
25
+ // Keep the in-memory theme usable when browser storage is unavailable.
26
+ }
27
+ setThemeState(nextTheme);
28
+ }, []);
29
+
30
+ const value = useMemo(() => ({ theme, setTheme }), [theme, setTheme]);
31
+
32
+ return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
33
+ }
34
+
35
+ export function useTheme() {
36
+ const context = useContext(ThemeContext);
37
+ if (!context) {
38
+ throw new Error("useTheme must be used within ThemeProvider.");
39
+ }
40
+ return context;
41
+ }
@@ -0,0 +1,21 @@
1
+ import { Moon, Sun } from "lucide-react";
2
+
3
+ import { Switch } from "@clubedge/ui/components/switch";
4
+ import { useTheme } from "./theme-provider";
5
+
6
+ export function ThemeToggle() {
7
+ const { theme, setTheme } = useTheme();
8
+
9
+ return (
10
+ <div className="flex items-center gap-2">
11
+ <Sun aria-hidden="true" className="size-4 text-muted-foreground" />
12
+ <Switch
13
+ aria-label="Toggle dark theme"
14
+ checked={theme === "dark"}
15
+ onCheckedChange={(checked) => setTheme(checked ? "dark" : "light")}
16
+ />
17
+ <Moon aria-hidden="true" className="size-4 text-muted-foreground" />
18
+ <span className="sr-only">Theme: {theme}</span>
19
+ </div>
20
+ );
21
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "Clubedge Starter",
3
+ "shortName": "Clubedge",
4
+ "description": "A production-minded foundation for Clubedge applications.",
5
+ "serviceId": "clubedge-starter",
6
+ "workspaceLabel": "Starter workspace",
7
+ "links": {
8
+ "repository": "https://github.com/Clubedge/clubedge-starter",
9
+ "setupGuide": "https://github.com/Clubedge/clubedge-starter/blob/main/SETUP.md"
10
+ }
11
+ }
@@ -0,0 +1,20 @@
1
+ import site from "./site.json";
2
+
3
+ /**
4
+ * Project identity. Values live in site.json so tooling such as create-clubedge-app
5
+ * can rename a project by editing data instead of rewriting source files.
6
+ */
7
+ export interface SiteConfig {
8
+ name: string;
9
+ shortName: string;
10
+ description: string;
11
+ /** Machine-readable service name reported by health checks and logs. */
12
+ serviceId: string;
13
+ workspaceLabel: string;
14
+ links: {
15
+ repository: string;
16
+ setupGuide: string;
17
+ };
18
+ }
19
+
20
+ export const siteConfig: SiteConfig = site;
@@ -0,0 +1,26 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { getSupabaseAuthEnv } from "./auth";
3
+
4
+ describe("getSupabaseAuthEnv", () => {
5
+ afterEach(() => {
6
+ vi.unstubAllEnvs();
7
+ });
8
+
9
+ it("reports Supabase Auth only when both values are present", () => {
10
+ vi.stubEnv("SUPABASE_URL", "https://project.supabase.co");
11
+ vi.stubEnv("SUPABASE_PUBLISHABLE_KEY", "");
12
+ expect(getSupabaseAuthEnv()).toBeNull();
13
+
14
+ vi.stubEnv("SUPABASE_PUBLISHABLE_KEY", "sb_publishable_123");
15
+ expect(getSupabaseAuthEnv()).toEqual({
16
+ url: "https://project.supabase.co",
17
+ publishableKey: "sb_publishable_123",
18
+ });
19
+ });
20
+
21
+ it("rejects a malformed URL", () => {
22
+ vi.stubEnv("SUPABASE_URL", "not a url");
23
+ vi.spyOn(console, "error").mockImplementation(() => {});
24
+ expect(() => getSupabaseAuthEnv()).toThrow("Supabase Auth environment validation failed");
25
+ });
26
+ });
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { optional, parseEnv } from "./server";
3
+ // clubedge:if auth=better-auth
4
+ import { getAppUrl } from "./server";
5
+ // clubedge:end
6
+
7
+ // All auth runs on the server, so these variables need no browser prefix.
8
+
9
+ // clubedge:if auth=supabase
10
+ const supabaseAuthSchema = z.object({
11
+ SUPABASE_URL: optional(z.url()),
12
+ SUPABASE_PUBLISHABLE_KEY: optional(z.string()),
13
+ });
14
+
15
+ export interface SupabaseAuthEnv {
16
+ url: string;
17
+ publishableKey: string;
18
+ }
19
+
20
+ /** Supabase Auth settings, or null while they are not configured. */
21
+ export function getSupabaseAuthEnv(): SupabaseAuthEnv | null {
22
+ const env = parseEnv(supabaseAuthSchema, "Supabase Auth");
23
+ const url = env.SUPABASE_URL;
24
+ const publishableKey = env.SUPABASE_PUBLISHABLE_KEY;
25
+ return url && publishableKey ? { url, publishableKey } : null;
26
+ }
27
+ // clubedge:end
28
+
29
+ // clubedge:if auth=better-auth
30
+ const betterAuthSchema = z.object({
31
+ BETTER_AUTH_SECRET: optional(
32
+ z.string().min(32, "BETTER_AUTH_SECRET needs at least 32 characters"),
33
+ ),
34
+ });
35
+
36
+ export interface BetterAuthEnv {
37
+ secret: string;
38
+ baseUrl: string;
39
+ }
40
+
41
+ /** Better Auth settings, or null until BETTER_AUTH_SECRET is set. */
42
+ export function getBetterAuthEnv(): BetterAuthEnv | null {
43
+ const env = parseEnv(betterAuthSchema, "Better Auth");
44
+ return env.BETTER_AUTH_SECRET ? { secret: env.BETTER_AUTH_SECRET, baseUrl: getAppUrl() } : null;
45
+ }
46
+ // clubedge:end
@@ -0,0 +1,32 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+
3
+ async function loadFreshModule() {
4
+ vi.resetModules();
5
+ return import("./server");
6
+ }
7
+
8
+ describe("server env", () => {
9
+ afterEach(() => {
10
+ vi.unstubAllEnvs();
11
+ });
12
+
13
+ it("does not validate at import time", async () => {
14
+ vi.stubEnv("DATABASE_URL", "");
15
+ await expect(loadFreshModule()).resolves.toBeDefined();
16
+ });
17
+
18
+ it("throws on first use when required variables are missing", async () => {
19
+ vi.stubEnv("DATABASE_URL", "");
20
+ const { getServerEnv } = await loadFreshModule();
21
+ vi.spyOn(console, "error").mockImplementation(() => {});
22
+ expect(() => getServerEnv()).toThrow("Server environment validation failed");
23
+ });
24
+
25
+ it("defaults APP_URL for local development", async () => {
26
+ const { getAppUrl } = await loadFreshModule();
27
+ vi.stubEnv("APP_URL", "");
28
+ expect(getAppUrl()).toBe("http://localhost:3000");
29
+ vi.stubEnv("APP_URL", "https://app.example");
30
+ expect(getAppUrl()).toBe("https://app.example");
31
+ });
32
+ });
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+
3
+ /** An optional variable that may also be present but empty, as in a copied .env.example. */
4
+ export const optional = <T extends z.ZodType>(schema: T) => schema.optional().or(z.literal(""));
5
+
6
+ /**
7
+ * Validates one module's variables, naming the module in the error. Each provider module in
8
+ * src/server declares its own schema, so a project without that module has no such variables.
9
+ */
10
+ export function parseEnv<T extends z.ZodType>(schema: T, module: string): z.infer<T> {
11
+ const parsed = schema.safeParse(process.env);
12
+ if (!parsed.success) {
13
+ console.error(`Invalid ${module} environment:`, z.treeifyError(parsed.error));
14
+ throw new Error(`${module} environment validation failed. Check your .env.local file.`);
15
+ }
16
+ return parsed.data;
17
+ }
18
+
19
+ const serverSchema = z.object({
20
+ NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
21
+ APP_URL: z.url().default("http://localhost:3000"),
22
+ DATABASE_URL: z.string().min(1, "DATABASE_URL is required"),
23
+ });
24
+
25
+ export type ServerEnv = z.infer<typeof serverSchema>;
26
+
27
+ let cached: ServerEnv | undefined;
28
+
29
+ /**
30
+ * Validates the core server variables on first use rather than at import, so pages that never
31
+ * touch the database can build and render without them.
32
+ */
33
+ export function getServerEnv(): ServerEnv {
34
+ cached ??= parseEnv(serverSchema, "Server");
35
+ return cached;
36
+ }
37
+
38
+ /** The public origin used in emailed links. Validates only APP_URL. */
39
+ export function getAppUrl(): string {
40
+ const parsed = serverSchema.shape.APP_URL.safeParse(process.env.APP_URL || undefined);
41
+ if (!parsed.success) throw new Error("APP_URL must be an absolute URL.");
42
+ return parsed.data;
43
+ }
@@ -0,0 +1,16 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { loginUrl } from "./login-url";
3
+
4
+ describe("loginUrl", () => {
5
+ it("builds the plain login path", () => {
6
+ expect(loginUrl()).toBe("/login");
7
+ });
8
+
9
+ it("omits the default destination and encodes everything else", () => {
10
+ expect(loginUrl({ next: "/dashboard" })).toBe("/login");
11
+ expect(loginUrl({ mode: "signup", error: "invalid-input", next: "/a?b=c" })).toBe(
12
+ "/login?mode=signup&error=invalid-input&next=%2Fa%3Fb%3Dc",
13
+ );
14
+ expect(loginUrl({ mode: "signup", checkEmail: true })).toBe("/login?mode=signup&check-email=1");
15
+ });
16
+ });
@@ -0,0 +1,16 @@
1
+ type LoginUrlOptions = {
2
+ mode?: "signin" | "signup";
3
+ error?: string;
4
+ next?: string;
5
+ checkEmail?: boolean;
6
+ };
7
+
8
+ export function loginUrl({ mode = "signin", error, next, checkEmail }: LoginUrlOptions = {}) {
9
+ const params = new URLSearchParams();
10
+ if (mode === "signup") params.set("mode", "signup");
11
+ if (error) params.set("error", error);
12
+ if (checkEmail) params.set("check-email", "1");
13
+ if (next && next !== "/dashboard") params.set("next", next);
14
+ const query = params.toString();
15
+ return query ? `/login?${query}` : "/login";
16
+ }