create-launchrail 0.0.0-stage → 0.3.1
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.
- package/README.md +39 -2
- package/THIRD_PARTY_LICENSES +43 -0
- package/bin/create-launchrail.mjs +75 -0
- package/bin/project-directory.mjs +7 -0
- package/bin/scaffold.mjs +217 -0
- package/bin/tools.mjs +62 -0
- package/bin/versions.mjs +118 -0
- package/package.json +23 -4
- package/presets/headless/web/ui/button.tsx +16 -0
- package/presets/headless/web/ui/card.tsx +25 -0
- package/template/AGENTS.md +3 -0
- package/template/README.md +3 -0
- package/template/THIRD_PARTY_LICENSES +43 -0
- package/template/apps/mobile/AGENTS.md +11 -0
- package/template/apps/mobile/App.tsx +511 -0
- package/template/apps/mobile/app.json +14 -0
- package/template/apps/mobile/components.json +22 -0
- package/template/apps/mobile/global.css +54 -0
- package/template/apps/mobile/index.ts +4 -0
- package/template/apps/mobile/metro.config.js +7 -0
- package/template/apps/mobile/package.json +47 -0
- package/template/apps/mobile/src/auth.ts +19 -0
- package/template/apps/mobile/src/components/native-controls.tsx +12 -0
- package/template/apps/mobile/src/components/ui/button.tsx +108 -0
- package/template/apps/mobile/src/components/ui/card.tsx +66 -0
- package/template/apps/mobile/src/components/ui/input.tsx +33 -0
- package/template/apps/mobile/src/components/ui/text.tsx +89 -0
- package/template/apps/mobile/src/css.d.ts +1 -0
- package/template/apps/mobile/src/lib/utils.ts +6 -0
- package/template/apps/mobile/src/query.tsx +16 -0
- package/template/apps/mobile/src/server-url.ts +20 -0
- package/template/apps/mobile/src/trpc.tsx +47 -0
- package/template/apps/mobile/src/uniwind-types.d.ts +7 -0
- package/template/apps/mobile/tsconfig.json +21 -0
- package/template/apps/web/components.json +15 -0
- package/template/apps/web/drizzle/0000_auth.sql +53 -0
- package/template/apps/web/drizzle/meta/0000_snapshot.json +374 -0
- package/template/apps/web/drizzle/meta/_journal.json +13 -0
- package/template/apps/web/drizzle.config.ts +11 -0
- package/template/apps/web/next.config.ts +11 -0
- package/template/apps/web/package.json +48 -0
- package/template/apps/web/postcss.config.mjs +3 -0
- package/template/apps/web/src/app/api/auth/[...all]/route.ts +7 -0
- package/template/apps/web/src/app/api/trpc/[trpc]/route.ts +53 -0
- package/template/apps/web/src/app/globals.css +250 -0
- package/template/apps/web/src/app/layout.tsx +31 -0
- package/template/apps/web/src/app/page.tsx +35 -0
- package/template/apps/web/src/app/starter-demo.tsx +258 -0
- package/template/apps/web/src/components/ui/button.tsx +57 -0
- package/template/apps/web/src/components/ui/card.tsx +102 -0
- package/template/apps/web/src/lib/auth-client.ts +5 -0
- package/template/apps/web/src/lib/query.tsx +23 -0
- package/template/apps/web/src/lib/trpc.tsx +29 -0
- package/template/apps/web/src/lib/utils.ts +6 -0
- package/template/apps/web/src/server/auth.ts +44 -0
- package/template/apps/web/src/server/db.ts +38 -0
- package/template/apps/web/src/server/schema.ts +87 -0
- package/template/apps/web/tsconfig.json +31 -0
- package/template/compose.yaml +18 -0
- package/template/gitignore.template +32 -0
- package/template/package.json +22 -0
- package/template/packages/api/package.json +21 -0
- package/template/packages/api/src/hello.ts +5 -0
- package/template/packages/api/src/index.ts +45 -0
- package/template/packages/api/tsconfig.json +4 -0
- package/template/pnpm-workspace.yaml +5 -0
- package/template/theme/tokens.css +40 -0
- package/template/tsconfig.base.json +14 -0
- package/template/turbo.json +12 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/* @if tailwind */
|
|
2
|
+
@import "tailwindcss";
|
|
3
|
+
/* @if shadcn */
|
|
4
|
+
@import "../../../../theme/tokens.css";
|
|
5
|
+
@import "tw-animate-css";
|
|
6
|
+
@import "shadcn/tailwind.css";
|
|
7
|
+
|
|
8
|
+
@custom-variant dark {
|
|
9
|
+
&:where(.dark, .dark *) { @slot; }
|
|
10
|
+
@media (prefers-color-scheme: dark) { &:where(:root:not(.light), :root:not(.light) *) { @slot; } }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@theme inline {
|
|
14
|
+
--font-heading: var(--font-sans);
|
|
15
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
16
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
17
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
18
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
19
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
20
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
21
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
22
|
+
--color-sidebar: var(--sidebar);
|
|
23
|
+
--color-chart-5: var(--chart-5);
|
|
24
|
+
--color-chart-4: var(--chart-4);
|
|
25
|
+
--color-chart-3: var(--chart-3);
|
|
26
|
+
--color-chart-2: var(--chart-2);
|
|
27
|
+
--color-chart-1: var(--chart-1);
|
|
28
|
+
--color-ring: var(--ring);
|
|
29
|
+
--color-input: var(--input);
|
|
30
|
+
--color-border: var(--border);
|
|
31
|
+
--color-destructive: var(--destructive);
|
|
32
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
33
|
+
--color-accent: var(--accent);
|
|
34
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
35
|
+
--color-muted: var(--muted);
|
|
36
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
37
|
+
--color-secondary: var(--secondary);
|
|
38
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
39
|
+
--color-primary: var(--primary);
|
|
40
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
41
|
+
--color-popover: var(--popover);
|
|
42
|
+
--color-card-foreground: var(--card-foreground);
|
|
43
|
+
--color-card: var(--card);
|
|
44
|
+
--color-foreground: var(--foreground);
|
|
45
|
+
--color-background: var(--background);
|
|
46
|
+
--radius-sm: calc(var(--radius) * 0.6);
|
|
47
|
+
--radius-md: calc(var(--radius) * 0.8);
|
|
48
|
+
--radius-lg: var(--radius);
|
|
49
|
+
--radius-xl: calc(var(--radius) * 1.4);
|
|
50
|
+
--radius-2xl: calc(var(--radius) * 1.8);
|
|
51
|
+
--radius-3xl: calc(var(--radius) * 2.2);
|
|
52
|
+
--radius-4xl: calc(var(--radius) * 2.6);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
:root {
|
|
56
|
+
|
|
57
|
+
--background: var(--color-brand-light-background);
|
|
58
|
+
--foreground: var(--color-brand-light-foreground);
|
|
59
|
+
--card: var(--color-brand-light-card);
|
|
60
|
+
--card-foreground: var(--color-brand-light-card-foreground);
|
|
61
|
+
--popover: var(--color-brand-light-popover);
|
|
62
|
+
--popover-foreground: var(--color-brand-light-popover-foreground);
|
|
63
|
+
--primary: var(--color-brand-light-primary);
|
|
64
|
+
--primary-foreground: var(--color-brand-light-primary-foreground);
|
|
65
|
+
--secondary: var(--color-brand-light-secondary);
|
|
66
|
+
--secondary-foreground: var(--color-brand-light-secondary-foreground);
|
|
67
|
+
--muted: var(--color-brand-light-muted);
|
|
68
|
+
--muted-foreground: var(--color-brand-light-muted-foreground);
|
|
69
|
+
--accent: var(--color-brand-light-accent);
|
|
70
|
+
--accent-foreground: var(--color-brand-light-accent-foreground);
|
|
71
|
+
--destructive: var(--color-brand-light-destructive);
|
|
72
|
+
--border: var(--color-brand-light-border);
|
|
73
|
+
--input: var(--color-brand-light-input);
|
|
74
|
+
--ring: var(--color-brand-light-ring);
|
|
75
|
+
--chart-1: oklch(0.87 0 0);
|
|
76
|
+
--chart-2: oklch(0.556 0 0);
|
|
77
|
+
--chart-3: oklch(0.439 0 0);
|
|
78
|
+
--chart-4: oklch(0.371 0 0);
|
|
79
|
+
--chart-5: oklch(0.269 0 0);
|
|
80
|
+
--radius: var(--radius-launchrail);
|
|
81
|
+
--sidebar: oklch(0.985 0 0);
|
|
82
|
+
--sidebar-foreground: oklch(0.145 0 0);
|
|
83
|
+
--sidebar-primary: oklch(0.205 0 0);
|
|
84
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
85
|
+
--sidebar-accent: oklch(0.97 0 0);
|
|
86
|
+
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
87
|
+
--sidebar-border: oklch(0.922 0 0);
|
|
88
|
+
--sidebar-ring: oklch(0.708 0 0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.dark {
|
|
92
|
+
|
|
93
|
+
--background: var(--color-brand-dark-background);
|
|
94
|
+
--foreground: var(--color-brand-dark-foreground);
|
|
95
|
+
--card: var(--color-brand-dark-card);
|
|
96
|
+
--card-foreground: var(--color-brand-dark-card-foreground);
|
|
97
|
+
--popover: var(--color-brand-dark-popover);
|
|
98
|
+
--popover-foreground: var(--color-brand-dark-popover-foreground);
|
|
99
|
+
--primary: var(--color-brand-dark-primary);
|
|
100
|
+
--primary-foreground: var(--color-brand-dark-primary-foreground);
|
|
101
|
+
--secondary: var(--color-brand-dark-secondary);
|
|
102
|
+
--secondary-foreground: var(--color-brand-dark-secondary-foreground);
|
|
103
|
+
--muted: var(--color-brand-dark-muted);
|
|
104
|
+
--muted-foreground: var(--color-brand-dark-muted-foreground);
|
|
105
|
+
--accent: var(--color-brand-dark-accent);
|
|
106
|
+
--accent-foreground: var(--color-brand-dark-accent-foreground);
|
|
107
|
+
--destructive: var(--color-brand-dark-destructive);
|
|
108
|
+
--border: var(--color-brand-dark-border);
|
|
109
|
+
--input: var(--color-brand-dark-input);
|
|
110
|
+
--ring: var(--color-brand-dark-ring);
|
|
111
|
+
--chart-1: oklch(0.87 0 0);
|
|
112
|
+
--chart-2: oklch(0.556 0 0);
|
|
113
|
+
--chart-3: oklch(0.439 0 0);
|
|
114
|
+
--chart-4: oklch(0.371 0 0);
|
|
115
|
+
--chart-5: oklch(0.269 0 0);
|
|
116
|
+
--sidebar: oklch(0.205 0 0);
|
|
117
|
+
--sidebar-foreground: oklch(0.985 0 0);
|
|
118
|
+
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
119
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
120
|
+
--sidebar-accent: oklch(0.269 0 0);
|
|
121
|
+
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
122
|
+
--sidebar-border: oklch(1 0 0 / 10%);
|
|
123
|
+
--sidebar-ring: oklch(0.556 0 0);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@media (prefers-color-scheme: dark) {
|
|
127
|
+
:root:not(.light) {
|
|
128
|
+
|
|
129
|
+
--background: var(--color-brand-dark-background);
|
|
130
|
+
--foreground: var(--color-brand-dark-foreground);
|
|
131
|
+
--card: var(--color-brand-dark-card);
|
|
132
|
+
--card-foreground: var(--color-brand-dark-card-foreground);
|
|
133
|
+
--popover: var(--color-brand-dark-popover);
|
|
134
|
+
--popover-foreground: var(--color-brand-dark-popover-foreground);
|
|
135
|
+
--primary: var(--color-brand-dark-primary);
|
|
136
|
+
--primary-foreground: var(--color-brand-dark-primary-foreground);
|
|
137
|
+
--secondary: var(--color-brand-dark-secondary);
|
|
138
|
+
--secondary-foreground: var(--color-brand-dark-secondary-foreground);
|
|
139
|
+
--muted: var(--color-brand-dark-muted);
|
|
140
|
+
--muted-foreground: var(--color-brand-dark-muted-foreground);
|
|
141
|
+
--accent: var(--color-brand-dark-accent);
|
|
142
|
+
--accent-foreground: var(--color-brand-dark-accent-foreground);
|
|
143
|
+
--destructive: var(--color-brand-dark-destructive);
|
|
144
|
+
--border: var(--color-brand-dark-border);
|
|
145
|
+
--input: var(--color-brand-dark-input);
|
|
146
|
+
--ring: var(--color-brand-dark-ring);
|
|
147
|
+
--chart-1: oklch(0.87 0 0);
|
|
148
|
+
--chart-2: oklch(0.556 0 0);
|
|
149
|
+
--chart-3: oklch(0.439 0 0);
|
|
150
|
+
--chart-4: oklch(0.371 0 0);
|
|
151
|
+
--chart-5: oklch(0.269 0 0);
|
|
152
|
+
--sidebar: oklch(0.205 0 0);
|
|
153
|
+
--sidebar-foreground: oklch(0.985 0 0);
|
|
154
|
+
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
155
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
156
|
+
--sidebar-accent: oklch(0.269 0 0);
|
|
157
|
+
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
158
|
+
--sidebar-border: oklch(1 0 0 / 10%);
|
|
159
|
+
--sidebar-ring: oklch(0.556 0 0);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@layer base {
|
|
164
|
+
* {
|
|
165
|
+
@apply border-border outline-ring/50;
|
|
166
|
+
}
|
|
167
|
+
body {
|
|
168
|
+
@apply bg-background text-foreground;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/* @else */
|
|
172
|
+
:root {
|
|
173
|
+
--background: oklch(0.99 0.003 85);
|
|
174
|
+
--foreground: oklch(0.22 0.015 55);
|
|
175
|
+
--primary: oklch(0.32 0.04 153);
|
|
176
|
+
--primary-foreground: oklch(0.99 0.003 85);
|
|
177
|
+
--muted: oklch(0.95 0.008 85);
|
|
178
|
+
--muted-foreground: oklch(0.46 0.019 65);
|
|
179
|
+
--destructive: oklch(0.56 0.20 28);
|
|
180
|
+
--border: oklch(0.87 0.012 85);
|
|
181
|
+
--ring: oklch(0.52 0.10 155);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@theme inline {
|
|
185
|
+
--color-background: var(--background);
|
|
186
|
+
--color-foreground: var(--foreground);
|
|
187
|
+
--color-primary: var(--primary);
|
|
188
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
189
|
+
--color-muted: var(--muted);
|
|
190
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
191
|
+
--color-destructive: var(--destructive);
|
|
192
|
+
--color-border: var(--border);
|
|
193
|
+
--color-ring: var(--ring);
|
|
194
|
+
}
|
|
195
|
+
/* @end */
|
|
196
|
+
|
|
197
|
+
/* @else */
|
|
198
|
+
:root { --background:#fff; --foreground:#141414; --border:#ddd; --ring:#222; }
|
|
199
|
+
/* @end */
|
|
200
|
+
|
|
201
|
+
body {
|
|
202
|
+
min-height: 100vh;
|
|
203
|
+
background: var(--background);
|
|
204
|
+
color: var(--foreground);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
label {
|
|
208
|
+
margin-bottom: -0.6rem;
|
|
209
|
+
font-size: 0.875rem;
|
|
210
|
+
font-weight: 550;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
input {
|
|
214
|
+
min-height: 2.5rem;
|
|
215
|
+
width: 100%;
|
|
216
|
+
border: 1px solid var(--border);
|
|
217
|
+
border-radius: 0.5rem;
|
|
218
|
+
background: var(--background);
|
|
219
|
+
padding: 0.5rem 0.75rem;
|
|
220
|
+
font: inherit;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.mode-toggle {
|
|
224
|
+
padding: 0.5rem 0.25rem;
|
|
225
|
+
font-size: 0.875rem;
|
|
226
|
+
text-decoration: underline;
|
|
227
|
+
text-underline-offset: 0.2rem;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
input:focus-visible,
|
|
231
|
+
.mode-toggle:focus-visible {
|
|
232
|
+
outline: 2px solid var(--ring);
|
|
233
|
+
outline-offset: 2px;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
* { box-sizing: border-box; }
|
|
237
|
+
body { margin: 0; font: 16px/1.55 system-ui,sans-serif; }
|
|
238
|
+
.starter-page { width: min(100% - 2.5rem, 66rem); margin-inline: auto; padding-block: 4rem; }
|
|
239
|
+
.starter-header h1 { font-size: clamp(2.75rem, 7vw, 5rem); letter-spacing: -.07em; line-height: .98; margin: 1.6rem 0 .8rem; }
|
|
240
|
+
.starter-header p { margin: 0 0 2rem; }
|
|
241
|
+
.starter-grid { display: grid; gap: 1.25rem; }
|
|
242
|
+
@media (min-width:48rem) { .starter-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
|
|
243
|
+
/* @if !shadcn */
|
|
244
|
+
[data-slot=card] { padding:1.25rem; border:1px solid var(--border); border-radius:.65rem; background:var(--background); }
|
|
245
|
+
[data-slot=card-title] { font-weight:650; }
|
|
246
|
+
[data-slot=card-description] { color:#595959; font-size:.9rem; margin:.2rem 0 1rem; }
|
|
247
|
+
[data-slot=button] { border:0; border-radius:.4rem; padding:.5rem .8rem; background:#171717; color:#fff; cursor:pointer; }
|
|
248
|
+
[data-slot=button]:disabled { opacity:.55; cursor:wait; }
|
|
249
|
+
[data-slot=card] form { display:grid; gap:1rem; margin-top:1rem; }
|
|
250
|
+
/* @end */
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Metadata } from "next";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
/* @if trpc */
|
|
5
|
+
import { Providers } from "@/lib/trpc";
|
|
6
|
+
/* @end */
|
|
7
|
+
/* @if !trpc */
|
|
8
|
+
/* @if query */
|
|
9
|
+
import { QueryProvider as Providers } from "@/lib/query";
|
|
10
|
+
/* @end */
|
|
11
|
+
/* @end */
|
|
12
|
+
import "./globals.css";
|
|
13
|
+
|
|
14
|
+
export const metadata: Metadata = {
|
|
15
|
+
title: "__PROJECT_NAME__",
|
|
16
|
+
description: "A Launchrail starter.",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
20
|
+
return (
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<body>
|
|
23
|
+
{/* @if query */}
|
|
24
|
+
<Providers>{children}</Providers>
|
|
25
|
+
{/* @else */}
|
|
26
|
+
{children}
|
|
27
|
+
{/* @end */}
|
|
28
|
+
</body>
|
|
29
|
+
</html>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* @if trpc */
|
|
2
|
+
import { GreetingDemo } from "./starter-demo";
|
|
3
|
+
/* @end */
|
|
4
|
+
/* @if auth */
|
|
5
|
+
import { AccountDemo } from "./starter-demo";
|
|
6
|
+
/* @end */
|
|
7
|
+
/* @if !trpc */
|
|
8
|
+
/* @if query */
|
|
9
|
+
import { QueryDemo } from "@/lib/query";
|
|
10
|
+
/* @end */
|
|
11
|
+
/* @end */
|
|
12
|
+
|
|
13
|
+
export default function Home() {
|
|
14
|
+
return (
|
|
15
|
+
<main className="starter-page">
|
|
16
|
+
<header className="starter-header">
|
|
17
|
+
<span>__PROJECT_NAME__</span>
|
|
18
|
+
<h1>Your web starter</h1>
|
|
19
|
+
<p>Start here or add your first route in <code>apps/web/src/app</code>.</p>
|
|
20
|
+
</header>
|
|
21
|
+
<div className="starter-grid">
|
|
22
|
+
{/* @if trpc */}
|
|
23
|
+
<GreetingDemo />
|
|
24
|
+
{/* @else */}
|
|
25
|
+
{/* @if query */}
|
|
26
|
+
<QueryDemo />
|
|
27
|
+
{/* @end */}
|
|
28
|
+
{/* @end */}
|
|
29
|
+
{/* @if auth */}
|
|
30
|
+
<AccountDemo />
|
|
31
|
+
{/* @end */}
|
|
32
|
+
</div>
|
|
33
|
+
</main>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/* @if trpc */
|
|
4
|
+
import { helloInput } from "@launchrail/api/hello";
|
|
5
|
+
/* @end */
|
|
6
|
+
import { Button } from "@/components/ui/button";
|
|
7
|
+
import {
|
|
8
|
+
Card,
|
|
9
|
+
CardContent,
|
|
10
|
+
CardDescription,
|
|
11
|
+
CardHeader,
|
|
12
|
+
CardTitle,
|
|
13
|
+
} from "@/components/ui/card";
|
|
14
|
+
/* @if trpc */
|
|
15
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
16
|
+
/* @end */
|
|
17
|
+
import { type FormEvent, useState } from "react";
|
|
18
|
+
|
|
19
|
+
/* @if auth */
|
|
20
|
+
import { authClient } from "@/lib/auth-client";
|
|
21
|
+
/* @end */
|
|
22
|
+
/* @if trpc */
|
|
23
|
+
import { useTRPC } from "@/lib/trpc";
|
|
24
|
+
/* @end */
|
|
25
|
+
|
|
26
|
+
/* @if trpc */
|
|
27
|
+
export function GreetingDemo() {
|
|
28
|
+
const trpc = useTRPC();
|
|
29
|
+
const [name, setName] = useState("Web");
|
|
30
|
+
const [submittedName, setSubmittedName] = useState("Web");
|
|
31
|
+
const [inputError, setInputError] = useState<string>();
|
|
32
|
+
const greeting = useQuery(trpc.hello.queryOptions({ name: submittedName }));
|
|
33
|
+
|
|
34
|
+
function submit(event: FormEvent<HTMLFormElement>) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
const parsed = helloInput.safeParse({ name });
|
|
37
|
+
if (!parsed.success) {
|
|
38
|
+
setInputError(parsed.error.issues[0]?.message ?? "Enter a valid name.");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setInputError(undefined);
|
|
42
|
+
if (parsed.data.name === submittedName) {
|
|
43
|
+
void greeting.refetch();
|
|
44
|
+
} else {
|
|
45
|
+
setSubmittedName(parsed.data.name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Card>
|
|
51
|
+
<CardHeader>
|
|
52
|
+
<CardTitle>Try the API</CardTitle>
|
|
53
|
+
<CardDescription>
|
|
54
|
+
Send a request to the public tRPC procedure.
|
|
55
|
+
</CardDescription>
|
|
56
|
+
</CardHeader>
|
|
57
|
+
<CardContent>
|
|
58
|
+
<form className="grid gap-4" onSubmit={submit}>
|
|
59
|
+
<label htmlFor="greeting-name">Name</label>
|
|
60
|
+
<input
|
|
61
|
+
id="greeting-name"
|
|
62
|
+
maxLength={80}
|
|
63
|
+
onChange={(event) => setName(event.target.value)}
|
|
64
|
+
required
|
|
65
|
+
value={name}
|
|
66
|
+
/>
|
|
67
|
+
<Button className="justify-self-start" type="submit">
|
|
68
|
+
Send request
|
|
69
|
+
</Button>
|
|
70
|
+
</form>
|
|
71
|
+
<div
|
|
72
|
+
className="mt-5 rounded-lg bg-muted px-4 py-3 text-sm"
|
|
73
|
+
role="status"
|
|
74
|
+
>
|
|
75
|
+
{inputError ?? greeting.data?.greeting ??
|
|
76
|
+
(greeting.isPending ? "Connecting to the API…" : "API unavailable")}
|
|
77
|
+
</div>
|
|
78
|
+
</CardContent>
|
|
79
|
+
</Card>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* @end */
|
|
84
|
+
|
|
85
|
+
/* @if auth */
|
|
86
|
+
export function AccountDemo() {
|
|
87
|
+
/* @if trpc */
|
|
88
|
+
const trpc = useTRPC();
|
|
89
|
+
const queryClient = useQueryClient();
|
|
90
|
+
/* @end */
|
|
91
|
+
const session = authClient.useSession();
|
|
92
|
+
const [mode, setMode] = useState<"sign-in" | "sign-up">("sign-in");
|
|
93
|
+
const [error, setError] = useState<string>();
|
|
94
|
+
const [pending, setPending] = useState(false);
|
|
95
|
+
/* @if trpc */
|
|
96
|
+
const account = useQuery(
|
|
97
|
+
trpc.account.me.queryOptions(undefined, { enabled: Boolean(session.data) }),
|
|
98
|
+
);
|
|
99
|
+
/* @end */
|
|
100
|
+
|
|
101
|
+
async function submit(event: FormEvent<HTMLFormElement>) {
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
const form = new FormData(event.currentTarget);
|
|
104
|
+
const email = String(form.get("email") ?? "");
|
|
105
|
+
const password = String(form.get("password") ?? "");
|
|
106
|
+
setError(undefined);
|
|
107
|
+
setPending(true);
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const result =
|
|
111
|
+
mode === "sign-up"
|
|
112
|
+
? await authClient.signUp.email({
|
|
113
|
+
email,
|
|
114
|
+
password,
|
|
115
|
+
name: String(form.get("name") ?? "").trim(),
|
|
116
|
+
})
|
|
117
|
+
: await authClient.signIn.email({ email, password });
|
|
118
|
+
|
|
119
|
+
if (result.error) {
|
|
120
|
+
setError(result.error.message ?? "Authentication failed.");
|
|
121
|
+
} else {
|
|
122
|
+
/* @if trpc */
|
|
123
|
+
queryClient.removeQueries({ queryKey: trpc.account.me.queryKey() });
|
|
124
|
+
/* @end */
|
|
125
|
+
await session.refetch();
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
setError("Could not reach the authentication server.");
|
|
129
|
+
} finally {
|
|
130
|
+
setPending(false);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function signOut() {
|
|
135
|
+
setError(undefined);
|
|
136
|
+
setPending(true);
|
|
137
|
+
try {
|
|
138
|
+
const result = await authClient.signOut();
|
|
139
|
+
if (result.error) {
|
|
140
|
+
setError(result.error.message ?? "Sign-out failed.");
|
|
141
|
+
} else {
|
|
142
|
+
/* @if trpc */
|
|
143
|
+
queryClient.removeQueries({ queryKey: trpc.account.me.queryKey() });
|
|
144
|
+
/* @end */
|
|
145
|
+
await session.refetch();
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
setError("Could not reach the authentication server.");
|
|
149
|
+
} finally {
|
|
150
|
+
setPending(false);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<Card>
|
|
156
|
+
<CardHeader>
|
|
157
|
+
<CardTitle>Account</CardTitle>
|
|
158
|
+
<CardDescription>
|
|
159
|
+
Sign in to manage your account.
|
|
160
|
+
</CardDescription>
|
|
161
|
+
</CardHeader>
|
|
162
|
+
<CardContent>
|
|
163
|
+
{session.isPending ? (
|
|
164
|
+
<p className="text-sm" role="status">
|
|
165
|
+
Checking session…
|
|
166
|
+
</p>
|
|
167
|
+
) : session.data ? (
|
|
168
|
+
<div className="grid gap-4">
|
|
169
|
+
<div
|
|
170
|
+
className="rounded-lg bg-muted px-4 py-3 text-sm"
|
|
171
|
+
role="status"
|
|
172
|
+
>
|
|
173
|
+
{/* @if trpc */}
|
|
174
|
+
{account.isError ? (
|
|
175
|
+
account.error.message
|
|
176
|
+
) : account.data ? (
|
|
177
|
+
<>
|
|
178
|
+
<p className="font-semibold">{account.data.name}</p>
|
|
179
|
+
<p>{account.data.email}</p>
|
|
180
|
+
</>
|
|
181
|
+
) : (
|
|
182
|
+
"Loading account…"
|
|
183
|
+
)}
|
|
184
|
+
{/* @else */}
|
|
185
|
+
<p className="font-semibold">{session.data.user.name}</p>
|
|
186
|
+
<p>{session.data.user.email}</p>
|
|
187
|
+
{/* @end */}
|
|
188
|
+
</div>
|
|
189
|
+
<Button
|
|
190
|
+
className="justify-self-start"
|
|
191
|
+
disabled={pending}
|
|
192
|
+
onClick={signOut}
|
|
193
|
+
type="button"
|
|
194
|
+
>
|
|
195
|
+
Sign out
|
|
196
|
+
</Button>
|
|
197
|
+
</div>
|
|
198
|
+
) : (
|
|
199
|
+
<form className="grid gap-4" onSubmit={submit}>
|
|
200
|
+
{mode === "sign-up" && (
|
|
201
|
+
<>
|
|
202
|
+
<label htmlFor="account-name">Name</label>
|
|
203
|
+
<input
|
|
204
|
+
autoComplete="name"
|
|
205
|
+
id="account-name"
|
|
206
|
+
maxLength={80}
|
|
207
|
+
name="name"
|
|
208
|
+
required
|
|
209
|
+
/>
|
|
210
|
+
</>
|
|
211
|
+
)}
|
|
212
|
+
<label htmlFor="account-email">Email</label>
|
|
213
|
+
<input
|
|
214
|
+
autoComplete="email"
|
|
215
|
+
id="account-email"
|
|
216
|
+
name="email"
|
|
217
|
+
required
|
|
218
|
+
type="email"
|
|
219
|
+
/>
|
|
220
|
+
<label htmlFor="account-password">Password</label>
|
|
221
|
+
<input
|
|
222
|
+
autoComplete={
|
|
223
|
+
mode === "sign-up" ? "new-password" : "current-password"
|
|
224
|
+
}
|
|
225
|
+
id="account-password"
|
|
226
|
+
minLength={8}
|
|
227
|
+
name="password"
|
|
228
|
+
required
|
|
229
|
+
type="password"
|
|
230
|
+
/>
|
|
231
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
232
|
+
<Button disabled={pending} type="submit">
|
|
233
|
+
{mode === "sign-up" ? "Create account" : "Sign in"}
|
|
234
|
+
</Button>
|
|
235
|
+
<button
|
|
236
|
+
className="mode-toggle"
|
|
237
|
+
disabled={pending}
|
|
238
|
+
onClick={() => {
|
|
239
|
+
setError(undefined);
|
|
240
|
+
setMode(mode === "sign-in" ? "sign-up" : "sign-in");
|
|
241
|
+
}}
|
|
242
|
+
type="button"
|
|
243
|
+
>
|
|
244
|
+
{mode === "sign-in" ? "Create an account" : "Back to sign in"}
|
|
245
|
+
</button>
|
|
246
|
+
</div>
|
|
247
|
+
</form>
|
|
248
|
+
)}
|
|
249
|
+
{error && (
|
|
250
|
+
<p className="mt-4 text-sm text-destructive" role="alert">
|
|
251
|
+
{error}
|
|
252
|
+
</p>
|
|
253
|
+
)}
|
|
254
|
+
</CardContent>
|
|
255
|
+
</Card>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
/* @end */
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
const buttonVariants = cva(
|
|
6
|
+
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
11
|
+
outline:
|
|
12
|
+
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
13
|
+
secondary:
|
|
14
|
+
"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
15
|
+
ghost:
|
|
16
|
+
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
17
|
+
destructive:
|
|
18
|
+
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
19
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
20
|
+
},
|
|
21
|
+
size: {
|
|
22
|
+
default:
|
|
23
|
+
"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
24
|
+
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
25
|
+
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
26
|
+
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
27
|
+
icon: "size-8",
|
|
28
|
+
"icon-xs":
|
|
29
|
+
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
|
30
|
+
"icon-sm":
|
|
31
|
+
"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
|
|
32
|
+
"icon-lg": "size-9",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
defaultVariants: {
|
|
36
|
+
variant: "default",
|
|
37
|
+
size: "default",
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
function Button({
|
|
43
|
+
className,
|
|
44
|
+
variant = "default",
|
|
45
|
+
size = "default",
|
|
46
|
+
...props
|
|
47
|
+
}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
|
|
48
|
+
return (
|
|
49
|
+
<ButtonPrimitive
|
|
50
|
+
data-slot="button"
|
|
51
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
52
|
+
{...props}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { Button, buttonVariants }
|