better-ts-stack 2.0.0 → 2.0.2
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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/args.js +2 -2
- package/dist/builder/buildPlanner.js +71 -0
- package/dist/builder/configGenerator.js +9 -7
- package/dist/builder/dependencyInstaller.js +0 -1
- package/dist/builder/fileProcessor.js +47 -44
- package/dist/builder/gitInitializer.js +20 -1
- package/dist/builder/index.js +19 -38
- package/dist/builder/moduleSelector.js +0 -1
- package/dist/builder/templateContext.js +0 -22
- package/dist/index.js +4 -3
- package/dist/modules/registry.js +4 -6
- package/dist/output/nextSteps.js +4 -3
- package/dist/prompts/index.js +0 -1
- package/dist/prompts/stack.js +4 -1
- package/dist/types/index.js +8 -4
- package/dist/ui/index.js +0 -1
- package/dist/ui/messages.js +25 -1
- package/dist/ui/prompts.js +0 -1
- package/dist/ui/theme.js +0 -1
- package/dist/validators/index.js +10 -41
- package/package.json +2 -1
- package/templates/backend/express/.prettierrc +2 -2
- package/templates/backend/express/config.json +1 -5
- package/templates/backend/express/eslint.config.mjs +40 -40
- package/templates/backend/express/gitignore +36 -36
- package/templates/backend/express/src/{index.ts → index.ts.hbs} +28 -29
- package/templates/backend/express/src/routes/health.ts +12 -12
- package/templates/backend/express/tsconfig.json +25 -25
- package/templates/backend/nestjs/.prettierrc +16 -16
- package/templates/backend/nestjs/config.json +1 -4
- package/templates/backend/nestjs/eslint.config.mjs +40 -40
- package/templates/backend/nestjs/gitignore +36 -36
- package/templates/backend/nestjs/nest-cli.json +9 -9
- package/templates/backend/nestjs/src/app.module.ts.hbs +34 -34
- package/templates/backend/nestjs/src/health/health.controller.ts +12 -12
- package/templates/backend/nestjs/src/main.ts +23 -23
- package/templates/backend/nestjs/tsconfig.json +25 -25
- package/templates/frontend/nextjs/components.json +19 -19
- package/templates/frontend/nextjs/config.json +1 -2
- package/templates/frontend/nextjs/gitignore +42 -42
- package/templates/frontend/nextjs/lib/utils.ts +6 -6
- package/templates/frontend/nextjs/proxy.ts.hbs +24 -24
- package/templates/frontend/nextjs/tsconfig.json +34 -34
- package/templates/frontend/tanstack/config.json +45 -48
- package/templates/frontend/tanstack/src/routeTree.gen.ts +68 -68
- package/templates/frontend/tanstack/src/styles/app.css +85 -85
- package/templates/modules/auth/express/config.json +1 -8
- package/templates/modules/auth/express/src/controllers/authController.ts.hbs +116 -116
- package/templates/modules/auth/express/src/middleware/requireAuth.ts.hbs +26 -26
- package/templates/modules/auth/express/src/services/userStore.ts.hbs +117 -117
- package/templates/modules/auth/nestjs/config.json +1 -5
- package/templates/modules/auth/nestjs/src/auth/auth.controller.ts +46 -46
- package/templates/modules/auth/nestjs/src/auth/auth.guard.ts +36 -36
- package/templates/modules/auth/nestjs/src/auth/auth.module.ts.hbs +22 -22
- package/templates/modules/auth/nestjs/src/auth/auth.schemas.ts +35 -35
- package/templates/modules/auth/nestjs/src/auth/auth.service.ts +70 -70
- package/templates/modules/auth/nestjs/src/auth/jwt.ts +27 -27
- package/templates/modules/auth/nestjs/src/auth/users.service.ts.hbs +144 -144
- package/templates/modules/auth/nestjs/src/auth/zod-validation.pipe.ts +16 -16
- package/templates/modules/auth/nextjs/app/dashboard/page.tsx +96 -96
- package/templates/modules/auth/nextjs/app/sign-in/page.tsx +35 -35
- package/templates/modules/auth/nextjs/app/sign-up/page.tsx +35 -35
- package/templates/modules/auth/nextjs/components/auth/sign-in-form.tsx +132 -132
- package/templates/modules/auth/nextjs/components/auth/sign-out-button.tsx +50 -50
- package/templates/modules/auth/nextjs/components/auth/sign-up-form.tsx +152 -152
- package/templates/modules/auth/nextjs/config.json +2 -15
- package/templates/modules/auth/nextjs/lib/auth-schema.ts +39 -39
- package/templates/modules/auth/nextjs/lib/auth.ts.hbs +37 -37
- package/templates/modules/auth/tanstack/config.json +2 -16
- package/templates/modules/auth/tanstack/src/lib/auth-functions.ts +4 -4
- package/templates/modules/auth/tanstack/src/lib/auth-schema.ts +38 -38
- package/templates/modules/auth/tanstack/src/routeTree.gen.ts +140 -140
- package/templates/modules/docker/.dockerignore +14 -14
- package/templates/modules/docker/Dockerfile.hbs +1 -3
- package/templates/modules/docker/config.json +1 -5
- package/templates/modules/docker/docker-compose.yml.hbs +9 -9
- package/templates/modules/drizzle/express/config.json +1 -2
- package/templates/modules/drizzle/express/drizzle.config.ts +13 -13
- package/templates/modules/drizzle/express/src/lib/db.ts +13 -13
- package/templates/modules/drizzle/express/src/lib/schema.ts +12 -10
- package/templates/modules/drizzle/nestjs/config.json +1 -2
- package/templates/modules/drizzle/nestjs/drizzle.config.ts +13 -13
- package/templates/modules/drizzle/nestjs/src/database/database.module.ts +30 -30
- package/templates/modules/drizzle/nestjs/src/database/schema.ts +12 -10
- package/templates/modules/drizzle/nextjs/config.json +1 -4
- package/templates/modules/drizzle/nextjs/lib/db.ts +13 -13
- package/templates/modules/drizzle/nextjs/lib/schema.ts.hbs +90 -84
- package/templates/modules/drizzle/tanstack/config.json +5 -5
- package/templates/modules/drizzle/tanstack/src/lib/schema.ts.hbs +90 -84
- package/templates/modules/mongoose/express/config.json +1 -2
- package/templates/modules/mongoose/nestjs/config.json +1 -2
- package/templates/modules/mongoose/nestjs/src/users/user.schema.ts +21 -21
- package/templates/modules/mongoose/nextjs/config.json +1 -2
- package/templates/modules/mongoose/nextjs/lib/db.ts +36 -36
- package/templates/modules/mongoose/tanstack/config.json +1 -2
- package/templates/modules/mongoose/tanstack/src/lib/db.ts +37 -37
- package/templates/modules/prisma/express/config.json +0 -1
- package/templates/modules/prisma/express/prisma/schema.prisma +1 -1
- package/templates/modules/prisma/express/prisma.config.ts +12 -12
- package/templates/modules/prisma/express/src/lib/prisma.ts +24 -24
- package/templates/modules/prisma/nestjs/config.json +0 -1
- package/templates/modules/prisma/nestjs/prisma/schema.prisma +23 -23
- package/templates/modules/prisma/nestjs/prisma.config.ts +12 -12
- package/templates/modules/prisma/nestjs/src/prisma/prisma.module.ts +11 -11
- package/templates/modules/prisma/nestjs/src/prisma/prisma.service.ts +17 -17
- package/templates/modules/prisma/nextjs/config.json +0 -1
- package/templates/modules/prisma/nextjs/prisma/schema.prisma.hbs +91 -91
- package/templates/modules/prisma/tanstack/config.json +0 -1
- package/dist/args.d.ts +0 -12
- package/dist/args.d.ts.map +0 -1
- package/dist/args.js.map +0 -1
- package/dist/builder/configGenerator.d.ts +0 -7
- package/dist/builder/configGenerator.d.ts.map +0 -1
- package/dist/builder/configGenerator.js.map +0 -1
- package/dist/builder/dependencyInstaller.d.ts +0 -3
- package/dist/builder/dependencyInstaller.d.ts.map +0 -1
- package/dist/builder/dependencyInstaller.js.map +0 -1
- package/dist/builder/fileProcessor.d.ts +0 -6
- package/dist/builder/fileProcessor.d.ts.map +0 -1
- package/dist/builder/fileProcessor.js.map +0 -1
- package/dist/builder/gitInitializer.d.ts +0 -2
- package/dist/builder/gitInitializer.d.ts.map +0 -1
- package/dist/builder/gitInitializer.js.map +0 -1
- package/dist/builder/index.d.ts +0 -3
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/moduleSelector.d.ts +0 -6
- package/dist/builder/moduleSelector.d.ts.map +0 -1
- package/dist/builder/moduleSelector.js.map +0 -1
- package/dist/builder/templateContext.d.ts +0 -6
- package/dist/builder/templateContext.d.ts.map +0 -1
- package/dist/builder/templateContext.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/modules/registry.d.ts +0 -6
- package/dist/modules/registry.d.ts.map +0 -1
- package/dist/modules/registry.js.map +0 -1
- package/dist/output/nextSteps.d.ts +0 -3
- package/dist/output/nextSteps.d.ts.map +0 -1
- package/dist/output/nextSteps.js.map +0 -1
- package/dist/prompts/index.d.ts +0 -4
- package/dist/prompts/index.d.ts.map +0 -1
- package/dist/prompts/index.js.map +0 -1
- package/dist/prompts/stack.d.ts +0 -4
- package/dist/prompts/stack.d.ts.map +0 -1
- package/dist/prompts/stack.js.map +0 -1
- package/dist/types/index.d.ts +0 -137
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/ui/index.d.ts +0 -3
- package/dist/ui/index.d.ts.map +0 -1
- package/dist/ui/index.js.map +0 -1
- package/dist/ui/messages.d.ts +0 -9
- package/dist/ui/messages.d.ts.map +0 -1
- package/dist/ui/messages.js.map +0 -1
- package/dist/ui/prompts.d.ts +0 -20
- package/dist/ui/prompts.d.ts.map +0 -1
- package/dist/ui/prompts.js.map +0 -1
- package/dist/ui/theme.d.ts +0 -9
- package/dist/ui/theme.d.ts.map +0 -1
- package/dist/ui/theme.js.map +0 -1
- package/dist/validators/index.d.ts +0 -6
- package/dist/validators/index.d.ts.map +0 -1
- package/dist/validators/index.js.map +0 -1
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useRouter } from "next/navigation";
|
|
4
|
-
import { useState, useTransition } from "react";
|
|
5
|
-
import { LoaderCircle, LogOut } from "lucide-react";
|
|
6
|
-
|
|
7
|
-
import { authClient } from "@/lib/auth-client";
|
|
8
|
-
import { Button } from "@/components/ui/button";
|
|
9
|
-
|
|
10
|
-
export function SignOutButton() {
|
|
11
|
-
const router = useRouter();
|
|
12
|
-
const [isPending, startTransition] = useTransition();
|
|
13
|
-
const [error, setError] = useState<string | null>(null);
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<div className="space-y-2">
|
|
17
|
-
<Button
|
|
18
|
-
variant="outline"
|
|
19
|
-
onClick={() => {
|
|
20
|
-
setError(null);
|
|
21
|
-
startTransition(async () => {
|
|
22
|
-
const result = await authClient.signOut();
|
|
23
|
-
|
|
24
|
-
if (result.error) {
|
|
25
|
-
setError("Unable to sign out right now. Please try again.");
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
router.push("/sign-in");
|
|
30
|
-
router.refresh();
|
|
31
|
-
});
|
|
32
|
-
}}
|
|
33
|
-
disabled={isPending}
|
|
34
|
-
>
|
|
35
|
-
{isPending ? (
|
|
36
|
-
<>
|
|
37
|
-
<LoaderCircle className="mr-2 size-4 animate-spin" />
|
|
38
|
-
Signing out
|
|
39
|
-
</>
|
|
40
|
-
) : (
|
|
41
|
-
<>
|
|
42
|
-
<LogOut className="mr-2 size-4" />
|
|
43
|
-
Sign out
|
|
44
|
-
</>
|
|
45
|
-
)}
|
|
46
|
-
</Button>
|
|
47
|
-
{error ? <p className="text-sm text-rose-600">{error}</p> : null}
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useRouter } from "next/navigation";
|
|
4
|
+
import { useState, useTransition } from "react";
|
|
5
|
+
import { LoaderCircle, LogOut } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
import { authClient } from "@/lib/auth-client";
|
|
8
|
+
import { Button } from "@/components/ui/button";
|
|
9
|
+
|
|
10
|
+
export function SignOutButton() {
|
|
11
|
+
const router = useRouter();
|
|
12
|
+
const [isPending, startTransition] = useTransition();
|
|
13
|
+
const [error, setError] = useState<string | null>(null);
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div className="space-y-2">
|
|
17
|
+
<Button
|
|
18
|
+
variant="outline"
|
|
19
|
+
onClick={() => {
|
|
20
|
+
setError(null);
|
|
21
|
+
startTransition(async () => {
|
|
22
|
+
const result = await authClient.signOut();
|
|
23
|
+
|
|
24
|
+
if (result.error) {
|
|
25
|
+
setError("Unable to sign out right now. Please try again.");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
router.push("/sign-in");
|
|
30
|
+
router.refresh();
|
|
31
|
+
});
|
|
32
|
+
}}
|
|
33
|
+
disabled={isPending}
|
|
34
|
+
>
|
|
35
|
+
{isPending ? (
|
|
36
|
+
<>
|
|
37
|
+
<LoaderCircle className="mr-2 size-4 animate-spin" />
|
|
38
|
+
Signing out
|
|
39
|
+
</>
|
|
40
|
+
) : (
|
|
41
|
+
<>
|
|
42
|
+
<LogOut className="mr-2 size-4" />
|
|
43
|
+
Sign out
|
|
44
|
+
</>
|
|
45
|
+
)}
|
|
46
|
+
</Button>
|
|
47
|
+
{error ? <p className="text-sm text-rose-600">{error}</p> : null}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import Link from "next/link";
|
|
4
|
-
import { useRouter } from "next/navigation";
|
|
5
|
-
import { useState, useTransition } from "react";
|
|
6
|
-
import { zodResolver } from "@hookform/resolvers/zod";
|
|
7
|
-
import { LoaderCircle } from "lucide-react";
|
|
8
|
-
import { useForm } from "react-hook-form";
|
|
9
|
-
|
|
10
|
-
import { authClient } from "@/lib/auth-client";
|
|
11
|
-
import {
|
|
12
|
-
getAuthErrorMessage,
|
|
13
|
-
signUpSchema,
|
|
14
|
-
type SignUpValues,
|
|
15
|
-
} from "@/lib/auth-schema";
|
|
16
|
-
import { Button } from "@/components/ui/button";
|
|
17
|
-
import {
|
|
18
|
-
Card,
|
|
19
|
-
CardContent,
|
|
20
|
-
CardDescription,
|
|
21
|
-
CardFooter,
|
|
22
|
-
CardHeader,
|
|
23
|
-
CardTitle,
|
|
24
|
-
} from "@/components/ui/card";
|
|
25
|
-
import {
|
|
26
|
-
Field,
|
|
27
|
-
FieldDescription,
|
|
28
|
-
FieldError,
|
|
29
|
-
FieldGroup,
|
|
30
|
-
FieldLabel,
|
|
31
|
-
} from "@/components/ui/field";
|
|
32
|
-
import { Input } from "@/components/ui/input";
|
|
33
|
-
|
|
34
|
-
export function SignUpForm() {
|
|
35
|
-
const router = useRouter();
|
|
36
|
-
const [isPending, startTransition] = useTransition();
|
|
37
|
-
const [authError, setAuthError] = useState<string | null>(null);
|
|
38
|
-
const form = useForm<SignUpValues>({
|
|
39
|
-
resolver: zodResolver(signUpSchema),
|
|
40
|
-
defaultValues: {
|
|
41
|
-
name: "",
|
|
42
|
-
email: "",
|
|
43
|
-
password: "",
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const onSubmit = form.handleSubmit((values) => {
|
|
48
|
-
setAuthError(null);
|
|
49
|
-
|
|
50
|
-
startTransition(async () => {
|
|
51
|
-
const result = await authClient.signUp.email({
|
|
52
|
-
name: values.name,
|
|
53
|
-
email: values.email,
|
|
54
|
-
password: values.password,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if (result.error) {
|
|
58
|
-
setAuthError(getAuthErrorMessage(result.error));
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
router.push("/dashboard");
|
|
63
|
-
router.refresh();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<Card className="border-white/80 bg-white/90 shadow-2xl shadow-slate-200/70 backdrop-blur">
|
|
69
|
-
<CardHeader className="space-y-2">
|
|
70
|
-
<CardTitle>Create your account</CardTitle>
|
|
71
|
-
<CardDescription>
|
|
72
|
-
Start with a simple email and password sign-up flow powered by Better
|
|
73
|
-
Auth.
|
|
74
|
-
</CardDescription>
|
|
75
|
-
</CardHeader>
|
|
76
|
-
<CardContent>
|
|
77
|
-
<form className="space-y-6" onSubmit={onSubmit} noValidate>
|
|
78
|
-
<FieldGroup>
|
|
79
|
-
<Field data-invalid={Boolean(form.formState.errors.name)}>
|
|
80
|
-
<FieldLabel htmlFor="name">Full name</FieldLabel>
|
|
81
|
-
<Input
|
|
82
|
-
id="name"
|
|
83
|
-
autoComplete="name"
|
|
84
|
-
aria-invalid={Boolean(form.formState.errors.name)}
|
|
85
|
-
placeholder="Ada Lovelace"
|
|
86
|
-
{...form.register("name")}
|
|
87
|
-
/>
|
|
88
|
-
<FieldError errors={[form.formState.errors.name]} />
|
|
89
|
-
</Field>
|
|
90
|
-
|
|
91
|
-
<Field data-invalid={Boolean(form.formState.errors.email)}>
|
|
92
|
-
<FieldLabel htmlFor="email">Email</FieldLabel>
|
|
93
|
-
<Input
|
|
94
|
-
id="email"
|
|
95
|
-
type="email"
|
|
96
|
-
autoComplete="email"
|
|
97
|
-
aria-invalid={Boolean(form.formState.errors.email)}
|
|
98
|
-
placeholder="you@example.com"
|
|
99
|
-
{...form.register("email")}
|
|
100
|
-
/>
|
|
101
|
-
<FieldDescription>
|
|
102
|
-
This email will be used for future sign-ins.
|
|
103
|
-
</FieldDescription>
|
|
104
|
-
<FieldError errors={[form.formState.errors.email]} />
|
|
105
|
-
</Field>
|
|
106
|
-
|
|
107
|
-
<Field data-invalid={Boolean(form.formState.errors.password)}>
|
|
108
|
-
<FieldLabel htmlFor="password">Password</FieldLabel>
|
|
109
|
-
<Input
|
|
110
|
-
id="password"
|
|
111
|
-
type="password"
|
|
112
|
-
autoComplete="new-password"
|
|
113
|
-
aria-invalid={Boolean(form.formState.errors.password)}
|
|
114
|
-
placeholder="Create a strong password"
|
|
115
|
-
{...form.register("password")}
|
|
116
|
-
/>
|
|
117
|
-
<FieldDescription>
|
|
118
|
-
Use at least 8 characters for the generated starter flow.
|
|
119
|
-
</FieldDescription>
|
|
120
|
-
<FieldError errors={[form.formState.errors.password]} />
|
|
121
|
-
</Field>
|
|
122
|
-
</FieldGroup>
|
|
123
|
-
|
|
124
|
-
{authError ? (
|
|
125
|
-
<div className="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700">
|
|
126
|
-
{authError}
|
|
127
|
-
</div>
|
|
128
|
-
) : null}
|
|
129
|
-
|
|
130
|
-
<Button className="w-full" type="submit" disabled={isPending}>
|
|
131
|
-
{isPending ? (
|
|
132
|
-
<>
|
|
133
|
-
<LoaderCircle className="mr-2 size-4 animate-spin" />
|
|
134
|
-
Creating account
|
|
135
|
-
</>
|
|
136
|
-
) : (
|
|
137
|
-
"Signup"
|
|
138
|
-
)}
|
|
139
|
-
</Button>
|
|
140
|
-
</form>
|
|
141
|
-
</CardContent>
|
|
142
|
-
<CardFooter className="justify-center">
|
|
143
|
-
<p className="text-sm text-slate-600">
|
|
144
|
-
Already have an account?{" "}
|
|
145
|
-
<Link className="font-medium text-sky-700 hover:text-sky-800" href="/sign-in">
|
|
146
|
-
Login
|
|
147
|
-
</Link>
|
|
148
|
-
</p>
|
|
149
|
-
</CardFooter>
|
|
150
|
-
</Card>
|
|
151
|
-
);
|
|
152
|
-
}
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
import { useRouter } from "next/navigation";
|
|
5
|
+
import { useState, useTransition } from "react";
|
|
6
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
7
|
+
import { LoaderCircle } from "lucide-react";
|
|
8
|
+
import { useForm } from "react-hook-form";
|
|
9
|
+
|
|
10
|
+
import { authClient } from "@/lib/auth-client";
|
|
11
|
+
import {
|
|
12
|
+
getAuthErrorMessage,
|
|
13
|
+
signUpSchema,
|
|
14
|
+
type SignUpValues,
|
|
15
|
+
} from "@/lib/auth-schema";
|
|
16
|
+
import { Button } from "@/components/ui/button";
|
|
17
|
+
import {
|
|
18
|
+
Card,
|
|
19
|
+
CardContent,
|
|
20
|
+
CardDescription,
|
|
21
|
+
CardFooter,
|
|
22
|
+
CardHeader,
|
|
23
|
+
CardTitle,
|
|
24
|
+
} from "@/components/ui/card";
|
|
25
|
+
import {
|
|
26
|
+
Field,
|
|
27
|
+
FieldDescription,
|
|
28
|
+
FieldError,
|
|
29
|
+
FieldGroup,
|
|
30
|
+
FieldLabel,
|
|
31
|
+
} from "@/components/ui/field";
|
|
32
|
+
import { Input } from "@/components/ui/input";
|
|
33
|
+
|
|
34
|
+
export function SignUpForm() {
|
|
35
|
+
const router = useRouter();
|
|
36
|
+
const [isPending, startTransition] = useTransition();
|
|
37
|
+
const [authError, setAuthError] = useState<string | null>(null);
|
|
38
|
+
const form = useForm<SignUpValues>({
|
|
39
|
+
resolver: zodResolver(signUpSchema),
|
|
40
|
+
defaultValues: {
|
|
41
|
+
name: "",
|
|
42
|
+
email: "",
|
|
43
|
+
password: "",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const onSubmit = form.handleSubmit((values) => {
|
|
48
|
+
setAuthError(null);
|
|
49
|
+
|
|
50
|
+
startTransition(async () => {
|
|
51
|
+
const result = await authClient.signUp.email({
|
|
52
|
+
name: values.name,
|
|
53
|
+
email: values.email,
|
|
54
|
+
password: values.password,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (result.error) {
|
|
58
|
+
setAuthError(getAuthErrorMessage(result.error));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
router.push("/dashboard");
|
|
63
|
+
router.refresh();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Card className="border-white/80 bg-white/90 shadow-2xl shadow-slate-200/70 backdrop-blur">
|
|
69
|
+
<CardHeader className="space-y-2">
|
|
70
|
+
<CardTitle>Create your account</CardTitle>
|
|
71
|
+
<CardDescription>
|
|
72
|
+
Start with a simple email and password sign-up flow powered by Better
|
|
73
|
+
Auth.
|
|
74
|
+
</CardDescription>
|
|
75
|
+
</CardHeader>
|
|
76
|
+
<CardContent>
|
|
77
|
+
<form className="space-y-6" onSubmit={onSubmit} noValidate>
|
|
78
|
+
<FieldGroup>
|
|
79
|
+
<Field data-invalid={Boolean(form.formState.errors.name)}>
|
|
80
|
+
<FieldLabel htmlFor="name">Full name</FieldLabel>
|
|
81
|
+
<Input
|
|
82
|
+
id="name"
|
|
83
|
+
autoComplete="name"
|
|
84
|
+
aria-invalid={Boolean(form.formState.errors.name)}
|
|
85
|
+
placeholder="Ada Lovelace"
|
|
86
|
+
{...form.register("name")}
|
|
87
|
+
/>
|
|
88
|
+
<FieldError errors={[form.formState.errors.name]} />
|
|
89
|
+
</Field>
|
|
90
|
+
|
|
91
|
+
<Field data-invalid={Boolean(form.formState.errors.email)}>
|
|
92
|
+
<FieldLabel htmlFor="email">Email</FieldLabel>
|
|
93
|
+
<Input
|
|
94
|
+
id="email"
|
|
95
|
+
type="email"
|
|
96
|
+
autoComplete="email"
|
|
97
|
+
aria-invalid={Boolean(form.formState.errors.email)}
|
|
98
|
+
placeholder="you@example.com"
|
|
99
|
+
{...form.register("email")}
|
|
100
|
+
/>
|
|
101
|
+
<FieldDescription>
|
|
102
|
+
This email will be used for future sign-ins.
|
|
103
|
+
</FieldDescription>
|
|
104
|
+
<FieldError errors={[form.formState.errors.email]} />
|
|
105
|
+
</Field>
|
|
106
|
+
|
|
107
|
+
<Field data-invalid={Boolean(form.formState.errors.password)}>
|
|
108
|
+
<FieldLabel htmlFor="password">Password</FieldLabel>
|
|
109
|
+
<Input
|
|
110
|
+
id="password"
|
|
111
|
+
type="password"
|
|
112
|
+
autoComplete="new-password"
|
|
113
|
+
aria-invalid={Boolean(form.formState.errors.password)}
|
|
114
|
+
placeholder="Create a strong password"
|
|
115
|
+
{...form.register("password")}
|
|
116
|
+
/>
|
|
117
|
+
<FieldDescription>
|
|
118
|
+
Use at least 8 characters for the generated starter flow.
|
|
119
|
+
</FieldDescription>
|
|
120
|
+
<FieldError errors={[form.formState.errors.password]} />
|
|
121
|
+
</Field>
|
|
122
|
+
</FieldGroup>
|
|
123
|
+
|
|
124
|
+
{authError ? (
|
|
125
|
+
<div className="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700">
|
|
126
|
+
{authError}
|
|
127
|
+
</div>
|
|
128
|
+
) : null}
|
|
129
|
+
|
|
130
|
+
<Button className="w-full" type="submit" disabled={isPending}>
|
|
131
|
+
{isPending ? (
|
|
132
|
+
<>
|
|
133
|
+
<LoaderCircle className="mr-2 size-4 animate-spin" />
|
|
134
|
+
Creating account
|
|
135
|
+
</>
|
|
136
|
+
) : (
|
|
137
|
+
"Signup"
|
|
138
|
+
)}
|
|
139
|
+
</Button>
|
|
140
|
+
</form>
|
|
141
|
+
</CardContent>
|
|
142
|
+
<CardFooter className="justify-center">
|
|
143
|
+
<p className="text-sm text-slate-600">
|
|
144
|
+
Already have an account?{" "}
|
|
145
|
+
<Link className="font-medium text-sky-700 hover:text-sky-800" href="/sign-in">
|
|
146
|
+
Login
|
|
147
|
+
</Link>
|
|
148
|
+
</p>
|
|
149
|
+
</CardFooter>
|
|
150
|
+
</Card>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
@@ -6,26 +6,13 @@
|
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@hookform/resolvers": "^5.9.1",
|
|
8
8
|
"better-auth": "^1.7.3",
|
|
9
|
-
"mongodb": "^7.6.0",
|
|
10
9
|
"react-hook-form": "^7.87.0",
|
|
11
|
-
"zod": "^4.5
|
|
10
|
+
"zod": "^4.6.5"
|
|
12
11
|
},
|
|
13
12
|
"devDependencies": {},
|
|
14
13
|
"scripts": {},
|
|
15
14
|
"envVars": {
|
|
16
15
|
"BETTER_AUTH_SECRET": "please-change-me-to-a-random-string",
|
|
17
16
|
"BETTER_AUTH_URL": "http://localhost:3000"
|
|
18
|
-
}
|
|
19
|
-
"templateFiles": [
|
|
20
|
-
"lib/auth.ts.hbs",
|
|
21
|
-
"lib/auth-client.ts",
|
|
22
|
-
"app/api/auth/[...all]/route.ts",
|
|
23
|
-
"app/dashboard/page.tsx",
|
|
24
|
-
"app/sign-in/page.tsx",
|
|
25
|
-
"app/sign-up/page.tsx",
|
|
26
|
-
"components/auth/sign-in-form.tsx",
|
|
27
|
-
"components/auth/sign-up-form.tsx",
|
|
28
|
-
"components/auth/sign-out-button.tsx",
|
|
29
|
-
"lib/auth-schema.ts"
|
|
30
|
-
]
|
|
17
|
+
}
|
|
31
18
|
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
export const signInSchema = z.object({
|
|
4
|
-
email: z.
|
|
5
|
-
password: z.string().min(8, "Password must be at least 8 characters."),
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export const signUpSchema = signInSchema.extend({
|
|
9
|
-
name: z
|
|
10
|
-
.string()
|
|
11
|
-
.trim()
|
|
12
|
-
.min(2, "Name must be at least 2 characters.")
|
|
13
|
-
.max(50, "Name must be 50 characters or fewer."),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export type SignInValues = z.infer<typeof signInSchema>;
|
|
17
|
-
export type SignUpValues = z.infer<typeof signUpSchema>;
|
|
18
|
-
|
|
19
|
-
export function getAuthErrorMessage(error: unknown) {
|
|
20
|
-
if (!error) {
|
|
21
|
-
return "Something went wrong. Please try again.";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (typeof error === "string") {
|
|
25
|
-
return error;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (typeof error === "object") {
|
|
29
|
-
if ("message" in error && typeof error.message === "string") {
|
|
30
|
-
return error.message;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if ("statusText" in error && typeof error.statusText === "string") {
|
|
34
|
-
return error.statusText;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return "Something went wrong. Please try again.";
|
|
39
|
-
}
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const signInSchema = z.object({
|
|
4
|
+
email: z.email("Enter a valid email address."),
|
|
5
|
+
password: z.string().min(8, "Password must be at least 8 characters."),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const signUpSchema = signInSchema.extend({
|
|
9
|
+
name: z
|
|
10
|
+
.string()
|
|
11
|
+
.trim()
|
|
12
|
+
.min(2, "Name must be at least 2 characters.")
|
|
13
|
+
.max(50, "Name must be 50 characters or fewer."),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export type SignInValues = z.infer<typeof signInSchema>;
|
|
17
|
+
export type SignUpValues = z.infer<typeof signUpSchema>;
|
|
18
|
+
|
|
19
|
+
export function getAuthErrorMessage(error: unknown) {
|
|
20
|
+
if (!error) {
|
|
21
|
+
return "Something went wrong. Please try again.";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof error === "string") {
|
|
25
|
+
return error;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof error === "object") {
|
|
29
|
+
if ("message" in error && typeof error.message === "string") {
|
|
30
|
+
return error.message;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if ("statusText" in error && typeof error.statusText === "string") {
|
|
34
|
+
return error.statusText;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return "Something went wrong. Please try again.";
|
|
39
|
+
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { betterAuth } from "better-auth";
|
|
2
|
-
import { nextCookies } from "better-auth/next-js";
|
|
3
|
-
{{#if (eq database 'prisma')}}
|
|
4
|
-
import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
5
|
-
import client from "./prisma";
|
|
6
|
-
{{/if}}
|
|
7
|
-
{{#if (eq database 'drizzle')}}
|
|
8
|
-
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
9
|
-
import { db } from "./db";
|
|
10
|
-
{{/if}}
|
|
11
|
-
{{#if (eq database 'mongoose')}}
|
|
12
|
-
import { mongodbAdapter } from "better-auth/adapters/mongodb";
|
|
13
|
-
import { MongoClient } from "mongodb";
|
|
14
|
-
|
|
15
|
-
const client = new MongoClient(process.env.MONGODB_URI!);
|
|
16
|
-
const db = client.db();
|
|
17
|
-
{{/if}}
|
|
18
|
-
|
|
19
|
-
export const auth = betterAuth({
|
|
20
|
-
{{#if (eq database 'prisma')}}
|
|
21
|
-
database: prismaAdapter(client, { provider: "postgresql" }),
|
|
22
|
-
{{/if}}
|
|
23
|
-
{{#if (eq database 'drizzle')}}
|
|
24
|
-
database: drizzleAdapter(db, { provider: "pg" }),
|
|
25
|
-
{{/if}}
|
|
26
|
-
{{#if (eq database 'mongoose')}}
|
|
27
|
-
// Transactions require a replica set. Create user/session/account/verification
|
|
28
|
-
// collections before the first sign-up; see the database setup documentation.
|
|
29
|
-
database: mongodbAdapter(db, { client }),
|
|
30
|
-
{{/if}}
|
|
31
|
-
emailAndPassword: {
|
|
32
|
-
enabled: true,
|
|
33
|
-
},
|
|
34
|
-
plugins: [nextCookies()],
|
|
35
|
-
secret: process.env.BETTER_AUTH_SECRET,
|
|
36
|
-
baseURL: process.env.BETTER_AUTH_URL,
|
|
37
|
-
});
|
|
1
|
+
import { betterAuth } from "better-auth";
|
|
2
|
+
import { nextCookies } from "better-auth/next-js";
|
|
3
|
+
{{#if (eq database 'prisma')}}
|
|
4
|
+
import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
5
|
+
import client from "./prisma";
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#if (eq database 'drizzle')}}
|
|
8
|
+
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
9
|
+
import { db } from "./db";
|
|
10
|
+
{{/if}}
|
|
11
|
+
{{#if (eq database 'mongoose')}}
|
|
12
|
+
import { mongodbAdapter } from "better-auth/adapters/mongodb";
|
|
13
|
+
import { MongoClient } from "mongodb";
|
|
14
|
+
|
|
15
|
+
const client = new MongoClient(process.env.MONGODB_URI!);
|
|
16
|
+
const db = client.db();
|
|
17
|
+
{{/if}}
|
|
18
|
+
|
|
19
|
+
export const auth = betterAuth({
|
|
20
|
+
{{#if (eq database 'prisma')}}
|
|
21
|
+
database: prismaAdapter(client, { provider: "postgresql" }),
|
|
22
|
+
{{/if}}
|
|
23
|
+
{{#if (eq database 'drizzle')}}
|
|
24
|
+
database: drizzleAdapter(db, { provider: "pg" }),
|
|
25
|
+
{{/if}}
|
|
26
|
+
{{#if (eq database 'mongoose')}}
|
|
27
|
+
// Transactions require a replica set. Create user/session/account/verification
|
|
28
|
+
// collections before the first sign-up; see the database setup documentation.
|
|
29
|
+
database: mongodbAdapter(db, { client }),
|
|
30
|
+
{{/if}}
|
|
31
|
+
emailAndPassword: {
|
|
32
|
+
enabled: true,
|
|
33
|
+
},
|
|
34
|
+
plugins: [nextCookies()],
|
|
35
|
+
secret: process.env.BETTER_AUTH_SECRET,
|
|
36
|
+
baseURL: process.env.BETTER_AUTH_URL,
|
|
37
|
+
});
|
|
@@ -7,27 +7,13 @@
|
|
|
7
7
|
"@hookform/resolvers": "^5.9.1",
|
|
8
8
|
"better-auth": "^1.7.3",
|
|
9
9
|
"dotenv": "^17.4.2",
|
|
10
|
-
"mongodb": "^7.6.0",
|
|
11
10
|
"react-hook-form": "^7.87.0",
|
|
12
|
-
"zod": "^4.5
|
|
11
|
+
"zod": "^4.6.5"
|
|
13
12
|
},
|
|
14
13
|
"devDependencies": {},
|
|
15
14
|
"scripts": {},
|
|
16
15
|
"envVars": {
|
|
17
16
|
"BETTER_AUTH_SECRET": "please-change-me-to-a-random-string",
|
|
18
17
|
"BETTER_AUTH_URL": "http://localhost:3000"
|
|
19
|
-
}
|
|
20
|
-
"templateFiles": [
|
|
21
|
-
"src/lib/auth.ts.hbs",
|
|
22
|
-
"src/lib/auth-client.ts",
|
|
23
|
-
"src/lib/auth-functions.ts",
|
|
24
|
-
"src/routes/api/auth/$.ts",
|
|
25
|
-
"src/routes/dashboard.tsx",
|
|
26
|
-
"src/routes/sign-in.tsx",
|
|
27
|
-
"src/routes/sign-up.tsx",
|
|
28
|
-
"src/components/auth/sign-in-form.tsx",
|
|
29
|
-
"src/components/auth/sign-up-form.tsx",
|
|
30
|
-
"src/components/auth/sign-out-button.tsx",
|
|
31
|
-
"src/lib/auth-schema.ts"
|
|
32
|
-
]
|
|
18
|
+
}
|
|
33
19
|
}
|
|
@@ -4,9 +4,9 @@ import { getRequestHeaders } from "@tanstack/react-start/server";
|
|
|
4
4
|
import { auth } from "./auth";
|
|
5
5
|
|
|
6
6
|
export const getSession = createServerFn({ method: "GET" }).handler(async () => {
|
|
7
|
-
const session = await auth.api.getSession({
|
|
8
|
-
headers: getRequestHeaders(),
|
|
9
|
-
});
|
|
7
|
+
const session = await auth.api.getSession({
|
|
8
|
+
headers: getRequestHeaders(),
|
|
9
|
+
});
|
|
10
10
|
|
|
11
11
|
return session;
|
|
12
|
-
});
|
|
12
|
+
});
|