better-ts-stack 2.1.2 → 2.2.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 (117) hide show
  1. package/README.md +16 -8
  2. package/dist/args.js +2 -1
  3. package/dist/builder/buildPlanner.js +7 -1
  4. package/dist/builder/configGenerator.js +28 -3
  5. package/dist/builder/index.js +2 -1
  6. package/dist/builder/readmeGenerator.js +2 -2
  7. package/dist/output/nextSteps.js +2 -4
  8. package/dist/prompts/stack.js +3 -5
  9. package/dist/types/index.js +1 -1
  10. package/package.json +1 -1
  11. package/templates/backend/express/src/env.ts.hbs +13 -2
  12. package/templates/backend/express/src/index.ts.hbs +31 -2
  13. package/templates/backend/nestjs/src/app.module.ts.hbs +4 -1
  14. package/templates/backend/nestjs/src/env.ts.hbs +13 -2
  15. package/templates/backend/nestjs/src/health/health.controller.ts.hbs +7 -0
  16. package/templates/backend/nestjs/src/{main.ts → main.ts.hbs} +11 -0
  17. package/templates/frontend/nextjs/app/globals.css +119 -79
  18. package/templates/frontend/nextjs/app/layout.tsx +13 -11
  19. package/templates/frontend/nextjs/app/page.tsx.hbs +63 -43
  20. package/templates/frontend/nextjs/components/ui/alert.tsx +75 -0
  21. package/templates/frontend/nextjs/components/ui/badge.tsx +51 -0
  22. package/templates/frontend/nextjs/components/ui/button.tsx +33 -27
  23. package/templates/frontend/nextjs/components/ui/card.tsx +76 -34
  24. package/templates/frontend/nextjs/components/ui/field.tsx +203 -32
  25. package/templates/frontend/nextjs/components/ui/input.tsx +8 -7
  26. package/templates/frontend/nextjs/components/ui/label.tsx +19 -0
  27. package/templates/frontend/nextjs/components/ui/separator.tsx +24 -0
  28. package/templates/frontend/nextjs/components/ui/skeleton.tsx +13 -0
  29. package/templates/frontend/nextjs/components/ui/spinner.tsx +10 -0
  30. package/templates/frontend/nextjs/components.json +11 -5
  31. package/templates/frontend/nextjs/config.json +4 -3
  32. package/templates/frontend/nextjs/lib/utils.ts +1 -6
  33. package/templates/frontend/tanstack/components.json +12 -5
  34. package/templates/frontend/tanstack/config.json +5 -2
  35. package/templates/frontend/tanstack/src/components/ui/alert.tsx +75 -0
  36. package/templates/frontend/tanstack/src/components/ui/badge.tsx +51 -0
  37. package/templates/frontend/tanstack/src/components/ui/button.tsx +33 -27
  38. package/templates/frontend/tanstack/src/components/ui/card.tsx +76 -34
  39. package/templates/frontend/tanstack/src/components/ui/field.tsx +201 -32
  40. package/templates/frontend/tanstack/src/components/ui/input.tsx +8 -7
  41. package/templates/frontend/tanstack/src/components/ui/label.tsx +17 -0
  42. package/templates/frontend/tanstack/src/components/ui/separator.tsx +24 -0
  43. package/templates/frontend/tanstack/src/components/ui/skeleton.tsx +13 -0
  44. package/templates/frontend/tanstack/src/components/ui/spinner.tsx +10 -0
  45. package/templates/frontend/tanstack/src/lib/utils.ts +1 -6
  46. package/templates/frontend/tanstack/src/routes/index.tsx.hbs +64 -45
  47. package/templates/frontend/tanstack/src/styles/app.css +100 -55
  48. package/templates/modules/agents/AGENTS.md.hbs +29 -21
  49. package/templates/modules/auth/express/config.json +12 -11
  50. package/templates/modules/auth/express/src/lib/auth.ts.hbs +143 -0
  51. package/templates/modules/auth/express/src/lib/email.ts +37 -0
  52. package/templates/modules/auth/express/src/middleware/requireAuth.ts +29 -0
  53. package/templates/modules/auth/express/src/routes/me.ts +13 -0
  54. package/templates/modules/auth/nestjs/config.json +13 -11
  55. package/templates/modules/auth/nestjs/src/auth/auth.module.ts.hbs +64 -14
  56. package/templates/modules/auth/nestjs/src/auth/auth.ts.hbs +152 -0
  57. package/templates/modules/auth/nestjs/src/auth/email.ts +37 -0
  58. package/templates/modules/auth/nestjs/src/me/me.controller.ts +15 -0
  59. package/templates/modules/auth/nextjs/app/dashboard/page.tsx +101 -45
  60. package/templates/modules/auth/nextjs/app/forgot-password/page.tsx +11 -0
  61. package/templates/modules/auth/nextjs/app/reset-password/page.tsx +17 -0
  62. package/templates/modules/auth/nextjs/app/sign-in/page.tsx +23 -17
  63. package/templates/modules/auth/nextjs/app/sign-up/page.tsx +25 -19
  64. package/templates/modules/auth/nextjs/components/auth/change-password-form.tsx +125 -0
  65. package/templates/modules/auth/nextjs/components/auth/email-verification-card.tsx +91 -0
  66. package/templates/modules/auth/nextjs/components/auth/forgot-password-form.tsx +133 -0
  67. package/templates/modules/auth/nextjs/components/auth/reset-password-form.tsx +155 -0
  68. package/templates/modules/auth/nextjs/components/auth/sign-in-form.tsx +46 -32
  69. package/templates/modules/auth/nextjs/components/auth/sign-out-button.tsx +6 -5
  70. package/templates/modules/auth/nextjs/components/auth/sign-up-form.tsx +36 -30
  71. package/templates/modules/auth/nextjs/components/auth/social-buttons.tsx +73 -0
  72. package/templates/modules/auth/nextjs/config.json +8 -2
  73. package/templates/modules/auth/nextjs/lib/auth-schema.ts +27 -2
  74. package/templates/modules/auth/nextjs/lib/auth.ts.hbs +65 -0
  75. package/templates/modules/auth/nextjs/lib/email.ts +43 -0
  76. package/templates/modules/auth/nextjs/lib/session.ts +12 -0
  77. package/templates/modules/auth/tanstack/config.json +9 -3
  78. package/templates/modules/auth/tanstack/src/components/auth/change-password-form.tsx +123 -0
  79. package/templates/modules/auth/tanstack/src/components/auth/email-verification-card.tsx +89 -0
  80. package/templates/modules/auth/tanstack/src/components/auth/forgot-password-form.tsx +131 -0
  81. package/templates/modules/auth/tanstack/src/components/auth/reset-password-form.tsx +149 -0
  82. package/templates/modules/auth/tanstack/src/components/auth/sign-in-form.tsx +44 -35
  83. package/templates/modules/auth/tanstack/src/components/auth/sign-out-button.tsx +7 -6
  84. package/templates/modules/auth/tanstack/src/components/auth/sign-up-form.tsx +37 -34
  85. package/templates/modules/auth/tanstack/src/components/auth/social-buttons.tsx +71 -0
  86. package/templates/modules/auth/tanstack/src/lib/auth-functions.ts +7 -1
  87. package/templates/modules/auth/tanstack/src/lib/auth-schema.ts +27 -2
  88. package/templates/modules/auth/tanstack/src/lib/auth.ts.hbs +61 -1
  89. package/templates/modules/auth/tanstack/src/lib/email.ts +43 -0
  90. package/templates/modules/auth/tanstack/src/routeTree.gen.ts +61 -3
  91. package/templates/modules/auth/tanstack/src/routes/dashboard.tsx +40 -32
  92. package/templates/modules/auth/tanstack/src/routes/forgot-password.tsx +17 -0
  93. package/templates/modules/auth/tanstack/src/routes/reset-password.tsx +25 -0
  94. package/templates/modules/auth/tanstack/src/routes/sign-in.tsx +19 -12
  95. package/templates/modules/auth/tanstack/src/routes/sign-up.tsx +21 -14
  96. package/templates/modules/drizzle/express/src/lib/schema.ts.hbs +90 -0
  97. package/templates/modules/drizzle/nestjs/src/database/schema.ts.hbs +90 -0
  98. package/templates/modules/mongoose/nestjs/config.json +2 -1
  99. package/templates/modules/prisma/express/prisma/schema.prisma.hbs +92 -0
  100. package/templates/modules/prisma/nestjs/prisma/schema.prisma.hbs +91 -0
  101. package/templates/modules/rate-limit/express/src/middleware/rateLimit.ts +0 -8
  102. package/templates/modules/auth/express/src/controllers/authController.ts.hbs +0 -116
  103. package/templates/modules/auth/express/src/lib/jwt.ts.hbs +0 -27
  104. package/templates/modules/auth/express/src/middleware/requireAuth.ts.hbs +0 -25
  105. package/templates/modules/auth/express/src/routes/auth.ts.hbs +0 -27
  106. package/templates/modules/auth/express/src/services/userStore.ts.hbs +0 -117
  107. package/templates/modules/auth/nestjs/src/auth/auth.controller.ts.hbs +0 -61
  108. package/templates/modules/auth/nestjs/src/auth/auth.guard.ts +0 -36
  109. package/templates/modules/auth/nestjs/src/auth/auth.schemas.ts +0 -35
  110. package/templates/modules/auth/nestjs/src/auth/auth.service.ts +0 -70
  111. package/templates/modules/auth/nestjs/src/auth/jwt.ts +0 -27
  112. package/templates/modules/auth/nestjs/src/auth/users.service.ts.hbs +0 -144
  113. package/templates/modules/auth/nestjs/src/auth/zod-validation.pipe.ts +0 -16
  114. package/templates/modules/drizzle/express/src/lib/schema.ts +0 -12
  115. package/templates/modules/drizzle/nestjs/src/database/schema.ts +0 -12
  116. package/templates/modules/prisma/express/prisma/schema.prisma +0 -24
  117. package/templates/modules/prisma/nestjs/prisma/schema.prisma +0 -23
@@ -1,7 +1,7 @@
1
1
  import { Link, useNavigate } from "@tanstack/react-router";
2
2
  import { useState, useTransition } from "react";
3
3
  import { zodResolver } from "@hookform/resolvers/zod";
4
- import { LoaderCircle } from "lucide-react";
4
+ import { CircleAlert } from "lucide-react";
5
5
  import { useForm } from "react-hook-form";
6
6
 
7
7
  import { authClient } from "~/lib/auth-client";
@@ -9,13 +9,14 @@ import {
9
9
  getAuthErrorMessage,
10
10
  signUpSchema,
11
11
  type SignUpValues,
12
+ type SocialProvider,
12
13
  } from "~/lib/auth-schema";
14
+ import { Alert, AlertDescription } from "~/components/ui/alert";
13
15
  import { Button } from "~/components/ui/button";
14
16
  import {
15
17
  Card,
16
18
  CardContent,
17
19
  CardDescription,
18
- CardFooter,
19
20
  CardHeader,
20
21
  CardTitle,
21
22
  } from "~/components/ui/card";
@@ -27,8 +28,11 @@ import {
27
28
  FieldLabel,
28
29
  } from "~/components/ui/field";
29
30
  import { Input } from "~/components/ui/input";
31
+ import { Spinner } from "~/components/ui/spinner";
30
32
 
31
- export function SignUpForm() {
33
+ import { SocialButtons } from "./social-buttons";
34
+
35
+ export function SignUpForm({ providers }: { providers: SocialProvider[] }) {
32
36
  const navigate = useNavigate();
33
37
  const [isPending, startTransition] = useTransition();
34
38
  const [authError, setAuthError] = useState<string | null>(null);
@@ -49,6 +53,8 @@ export function SignUpForm() {
49
53
  name: values.name,
50
54
  email: values.email,
51
55
  password: values.password,
56
+ // Where the link in the verification email leads after confirming
57
+ callbackURL: "/dashboard",
52
58
  });
53
59
 
54
60
  if (result.error) {
@@ -61,8 +67,8 @@ export function SignUpForm() {
61
67
  });
62
68
 
63
69
  return (
64
- <Card className="border-white/80 bg-white/90 shadow-2xl shadow-slate-200/70 backdrop-blur">
65
- <CardHeader className="space-y-2">
70
+ <Card>
71
+ <CardHeader>
66
72
  <CardTitle>Create your account</CardTitle>
67
73
  <CardDescription>
68
74
  Start with a simple email and password sign-up flow powered by Better
@@ -70,8 +76,10 @@ export function SignUpForm() {
70
76
  </CardDescription>
71
77
  </CardHeader>
72
78
  <CardContent>
73
- <form className="space-y-6" onSubmit={onSubmit} noValidate>
79
+ <form onSubmit={onSubmit} noValidate>
74
80
  <FieldGroup>
81
+ <SocialButtons providers={providers} />
82
+
75
83
  <Field data-invalid={Boolean(form.formState.errors.name)}>
76
84
  <FieldLabel htmlFor="name">Full name</FieldLabel>
77
85
  <Input
@@ -115,37 +123,32 @@ export function SignUpForm() {
115
123
  </FieldDescription>
116
124
  <FieldError errors={[form.formState.errors.password]} />
117
125
  </Field>
118
- </FieldGroup>
119
126
 
120
- {authError ? (
121
- <div className="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700">
122
- {authError}
123
- </div>
124
- ) : null}
127
+ {authError ? (
128
+ <Alert variant="destructive">
129
+ <CircleAlert />
130
+ <AlertDescription>{authError}</AlertDescription>
131
+ </Alert>
132
+ ) : null}
125
133
 
126
- <Button className="w-full" type="submit" disabled={isPending}>
127
- {isPending ? (
128
- <>
129
- <LoaderCircle className="mr-2 size-4 animate-spin" />
130
- Creating account
131
- </>
132
- ) : (
133
- "Signup"
134
- )}
135
- </Button>
134
+ <Field>
135
+ <Button type="submit" disabled={isPending}>
136
+ {isPending ? (
137
+ <>
138
+ <Spinner data-icon="inline-start" />
139
+ Creating account
140
+ </>
141
+ ) : (
142
+ "Signup"
143
+ )}
144
+ </Button>
145
+ <FieldDescription className="text-center">
146
+ Already have an account? <Link to="/sign-in">Login</Link>
147
+ </FieldDescription>
148
+ </Field>
149
+ </FieldGroup>
136
150
  </form>
137
151
  </CardContent>
138
- <CardFooter className="justify-center">
139
- <p className="text-sm text-slate-600">
140
- Already have an account?{" "}
141
- <Link
142
- className="font-medium text-sky-700 hover:text-sky-800"
143
- to="/sign-in"
144
- >
145
- Login
146
- </Link>
147
- </p>
148
- </CardFooter>
149
152
  </Card>
150
153
  );
151
- }
154
+ }
@@ -0,0 +1,71 @@
1
+ import { useState, useTransition } from "react";
2
+
3
+ import { authClient } from "~/lib/auth-client";
4
+ import { getAuthErrorMessage, type SocialProvider } from "~/lib/auth-schema";
5
+ import { Button } from "~/components/ui/button";
6
+ import { Field, FieldError, FieldSeparator } from "~/components/ui/field";
7
+ import { Spinner } from "~/components/ui/spinner";
8
+
9
+ const PROVIDER_LABELS: Record<SocialProvider, string> = {
10
+ github: "GitHub",
11
+ google: "Google",
12
+ };
13
+
14
+ // One button per provider turned on in lib/auth.ts; renders nothing when
15
+ // GitHub and Google sign-in are both off
16
+ export function SocialButtons({ providers }: { providers: SocialProvider[] }) {
17
+ const [isPending, startTransition] = useTransition();
18
+ // The provider whose button was clicked, for its "Redirecting" label
19
+ const [chosen, setChosen] = useState<SocialProvider | null>(null);
20
+ const [error, setError] = useState<string | null>(null);
21
+
22
+ if (providers.length === 0) {
23
+ return null;
24
+ }
25
+
26
+ function signIn(provider: SocialProvider) {
27
+ setError(null);
28
+ setChosen(provider);
29
+ startTransition(async () => {
30
+ // Redirects to the provider; the user comes back to the dashboard
31
+ const result = await authClient.signIn.social({
32
+ provider,
33
+ callbackURL: "/dashboard",
34
+ errorCallbackURL: "/sign-in",
35
+ });
36
+
37
+ if (result.error) {
38
+ setError(getAuthErrorMessage(result.error));
39
+ }
40
+ });
41
+ }
42
+
43
+ return (
44
+ <>
45
+ <Field data-invalid={Boolean(error)}>
46
+ {providers.map((provider) => (
47
+ <Button
48
+ key={provider}
49
+ type="button"
50
+ variant="outline"
51
+ disabled={isPending}
52
+ onClick={() => signIn(provider)}
53
+ >
54
+ {isPending && chosen === provider ? (
55
+ <>
56
+ <Spinner data-icon="inline-start" />
57
+ Redirecting
58
+ </>
59
+ ) : (
60
+ `Continue with ${PROVIDER_LABELS[provider]}`
61
+ )}
62
+ </Button>
63
+ ))}
64
+ {error ? <FieldError>{error}</FieldError> : null}
65
+ </Field>
66
+ <FieldSeparator className="*:data-[slot=field-separator-content]:bg-card">
67
+ Or continue with email
68
+ </FieldSeparator>
69
+ </>
70
+ );
71
+ }
@@ -1,7 +1,7 @@
1
1
  import { createServerFn } from "@tanstack/react-start";
2
2
  import { getRequestHeaders } from "@tanstack/react-start/server";
3
3
 
4
- import { auth } from "./auth";
4
+ import { auth, socialProviders } from "./auth";
5
5
 
6
6
  export const getSession = createServerFn({ method: "GET" }).handler(async () => {
7
7
  const session = await auth.api.getSession({
@@ -10,3 +10,9 @@ export const getSession = createServerFn({ method: "GET" }).handler(async () =>
10
10
 
11
11
  return session;
12
12
  });
13
+
14
+ // GitHub and Google, when their keys are set; read on the server, where the
15
+ // environment variables are
16
+ export const getSocialProviders = createServerFn({ method: "GET" }).handler(
17
+ () => socialProviders
18
+ );
@@ -1,8 +1,13 @@
1
1
  import { z } from "zod";
2
2
 
3
+ const emailSchema = z.email("Enter a valid email address.");
4
+ const passwordSchema = z
5
+ .string()
6
+ .min(8, "Password must be at least 8 characters.");
7
+
3
8
  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."),
9
+ email: emailSchema,
10
+ password: passwordSchema,
6
11
  });
7
12
 
8
13
  export const signUpSchema = signInSchema.extend({
@@ -13,8 +18,28 @@ export const signUpSchema = signInSchema.extend({
13
18
  .max(50, "Name must be 50 characters or fewer."),
14
19
  });
15
20
 
21
+ export const forgotPasswordSchema = z.object({ email: emailSchema });
22
+
23
+ export const resetPasswordSchema = z
24
+ .object({ password: passwordSchema, confirmPassword: z.string() })
25
+ .refine((values) => values.password === values.confirmPassword, {
26
+ message: "Passwords do not match.",
27
+ path: ["confirmPassword"],
28
+ });
29
+
30
+ export const changePasswordSchema = z.object({
31
+ currentPassword: z.string().min(1, "Enter your current password."),
32
+ newPassword: passwordSchema,
33
+ });
34
+
16
35
  export type SignInValues = z.infer<typeof signInSchema>;
17
36
  export type SignUpValues = z.infer<typeof signUpSchema>;
37
+ export type ForgotPasswordValues = z.infer<typeof forgotPasswordSchema>;
38
+ export type ResetPasswordValues = z.infer<typeof resetPasswordSchema>;
39
+ export type ChangePasswordValues = z.infer<typeof changePasswordSchema>;
40
+
41
+ // Sign-in providers the auth server can turn on (see auth.ts)
42
+ export type SocialProvider = "github" | "google";
18
43
 
19
44
  export function getAuthErrorMessage(error: unknown) {
20
45
  if (!error) {
@@ -1,6 +1,9 @@
1
1
  import "dotenv/config";
2
2
  import { betterAuth } from "better-auth";
3
3
  import { tanstackStartCookies } from "better-auth/tanstack-start";
4
+
5
+ import type { SocialProvider } from "./auth-schema";
6
+ import { sendEmail } from "./email";
4
7
  {{#if (eq database 'prisma')}}
5
8
  import { prismaAdapter } from "better-auth/adapters/prisma";
6
9
  import client from "./prisma";
@@ -17,6 +20,14 @@ const client = new MongoClient(process.env.MONGODB_URI!);
17
20
  const db = client.db();
18
21
  {{/if}}
19
22
 
23
+ // Reports a failed email instead of failing the request: the sign-up or reset
24
+ // already happened, and the user can ask for the email again
25
+ function deliver(email: Parameters<typeof sendEmail>[0]): void {
26
+ sendEmail(email).catch((error: unknown) => {
27
+ console.error(`Could not send "${email.subject}" to ${email.to}:`, error);
28
+ });
29
+ }
30
+
20
31
  export const auth = betterAuth({
21
32
  {{#if (eq database 'prisma')}}
22
33
  database: prismaAdapter(client, { provider: "postgresql" }),
@@ -31,8 +42,57 @@ export const auth = betterAuth({
31
42
  {{/if}}
32
43
  emailAndPassword: {
33
44
  enabled: true,
45
+ // Set to true to block sign-in until the email address is verified
46
+ requireEmailVerification: false,
47
+ // A reset signs the user out everywhere
48
+ revokeSessionsOnPasswordReset: true,
49
+ sendResetPassword: async ({ user, url }) => {
50
+ deliver({
51
+ to: user.email,
52
+ subject: "Reset your password",
53
+ text: `Open this link to choose a new password:
54
+ ${url}`,
55
+ });
56
+ },
57
+ },
58
+ emailVerification: {
59
+ sendOnSignUp: true,
60
+ autoSignInAfterVerification: true,
61
+ sendVerificationEmail: async ({ user, url }) => {
62
+ deliver({
63
+ to: user.email,
64
+ subject: "Verify your email address",
65
+ text: `Open this link to verify your email address:
66
+ ${url}`,
67
+ });
68
+ },
69
+ },
70
+ // Each provider is turned on once its client ID and secret are set
71
+ socialProviders: {
72
+ ...(process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET
73
+ ? {
74
+ github: {
75
+ clientId: process.env.GITHUB_CLIENT_ID,
76
+ clientSecret: process.env.GITHUB_CLIENT_SECRET,
77
+ },
78
+ }
79
+ : {}),
80
+ ...(process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET
81
+ ? {
82
+ google: {
83
+ clientId: process.env.GOOGLE_CLIENT_ID,
84
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET,
85
+ },
86
+ }
87
+ : {}),
34
88
  },
35
89
  plugins: [tanstackStartCookies()],
36
90
  secret: process.env.BETTER_AUTH_SECRET,
37
91
  baseURL: process.env.BETTER_AUTH_URL,
38
- });
92
+ });
93
+
94
+ // The providers turned on above; the sign-in and sign-up pages show a button
95
+ // for each
96
+ export const socialProviders = Object.keys(
97
+ auth.options.socialProviders
98
+ ) as SocialProvider[];
@@ -0,0 +1,43 @@
1
+ // Sends through Resend when RESEND_API_KEY is set. Without it the email is
2
+ // printed to the server log, so verification and reset links can be copied
3
+ // from the terminal during development
4
+ export async function sendEmail({
5
+ to,
6
+ subject,
7
+ text,
8
+ }: {
9
+ to: string;
10
+ subject: string;
11
+ text: string;
12
+ }): Promise<void> {
13
+ const apiKey = process.env.RESEND_API_KEY;
14
+
15
+ if (!apiKey) {
16
+ console.log(`
17
+ --- Email to ${to}: ${subject}
18
+ ${text}
19
+ ---
20
+ `);
21
+ return;
22
+ }
23
+
24
+ const response = await fetch("https://api.resend.com/emails", {
25
+ method: "POST",
26
+ headers: {
27
+ Authorization: `Bearer ${apiKey}`,
28
+ "Content-Type": "application/json",
29
+ },
30
+ body: JSON.stringify({
31
+ from: process.env.EMAIL_FROM || "onboarding@resend.dev",
32
+ to,
33
+ subject,
34
+ text,
35
+ }),
36
+ });
37
+
38
+ if (!response.ok) {
39
+ throw new Error(
40
+ `Resend rejected the email (${response.status}): ${await response.text()}`
41
+ );
42
+ }
43
+ }
@@ -11,6 +11,8 @@
11
11
  import { Route as rootRouteImport } from './routes/__root'
12
12
  import { Route as IndexRouteImport } from './routes/index'
13
13
  import { Route as DashboardRouteImport } from './routes/dashboard'
14
+ import { Route as ForgotPasswordRouteImport } from './routes/forgot-password'
15
+ import { Route as ResetPasswordRouteImport } from './routes/reset-password'
14
16
  import { Route as SignInRouteImport } from './routes/sign-in'
15
17
  import { Route as SignUpRouteImport } from './routes/sign-up'
16
18
  import { Route as ApiAuthSplatRouteImport } from './routes/api/auth/$'
@@ -25,6 +27,16 @@ const DashboardRoute = DashboardRouteImport.update({
25
27
  path: '/dashboard',
26
28
  getParentRoute: () => rootRouteImport,
27
29
  } as any)
30
+ const ForgotPasswordRoute = ForgotPasswordRouteImport.update({
31
+ id: '/forgot-password',
32
+ path: '/forgot-password',
33
+ getParentRoute: () => rootRouteImport,
34
+ } as any)
35
+ const ResetPasswordRoute = ResetPasswordRouteImport.update({
36
+ id: '/reset-password',
37
+ path: '/reset-password',
38
+ getParentRoute: () => rootRouteImport,
39
+ } as any)
28
40
  const SignInRoute = SignInRouteImport.update({
29
41
  id: '/sign-in',
30
42
  path: '/sign-in',
@@ -44,6 +56,8 @@ const ApiAuthSplatRoute = ApiAuthSplatRouteImport.update({
44
56
  export interface FileRoutesByFullPath {
45
57
  '/': typeof IndexRoute
46
58
  '/dashboard': typeof DashboardRoute
59
+ '/forgot-password': typeof ForgotPasswordRoute
60
+ '/reset-password': typeof ResetPasswordRoute
47
61
  '/sign-in': typeof SignInRoute
48
62
  '/sign-up': typeof SignUpRoute
49
63
  '/api/auth/$': typeof ApiAuthSplatRoute
@@ -51,6 +65,8 @@ export interface FileRoutesByFullPath {
51
65
  export interface FileRoutesByTo {
52
66
  '/': typeof IndexRoute
53
67
  '/dashboard': typeof DashboardRoute
68
+ '/forgot-password': typeof ForgotPasswordRoute
69
+ '/reset-password': typeof ResetPasswordRoute
54
70
  '/sign-in': typeof SignInRoute
55
71
  '/sign-up': typeof SignUpRoute
56
72
  '/api/auth/$': typeof ApiAuthSplatRoute
@@ -59,21 +75,47 @@ export interface FileRoutesById {
59
75
  __root__: typeof rootRouteImport
60
76
  '/': typeof IndexRoute
61
77
  '/dashboard': typeof DashboardRoute
78
+ '/forgot-password': typeof ForgotPasswordRoute
79
+ '/reset-password': typeof ResetPasswordRoute
62
80
  '/sign-in': typeof SignInRoute
63
81
  '/sign-up': typeof SignUpRoute
64
82
  '/api/auth/$': typeof ApiAuthSplatRoute
65
83
  }
66
84
  export interface FileRouteTypes {
67
85
  fileRoutesByFullPath: FileRoutesByFullPath
68
- fullPaths: '/' | '/dashboard' | '/sign-in' | '/sign-up' | '/api/auth/$'
86
+ fullPaths:
87
+ | '/'
88
+ | '/dashboard'
89
+ | '/forgot-password'
90
+ | '/reset-password'
91
+ | '/sign-in'
92
+ | '/sign-up'
93
+ | '/api/auth/$'
69
94
  fileRoutesByTo: FileRoutesByTo
70
- to: '/' | '/dashboard' | '/sign-in' | '/sign-up' | '/api/auth/$'
71
- id: '__root__' | '/' | '/dashboard' | '/sign-in' | '/sign-up' | '/api/auth/$'
95
+ to:
96
+ | '/'
97
+ | '/dashboard'
98
+ | '/forgot-password'
99
+ | '/reset-password'
100
+ | '/sign-in'
101
+ | '/sign-up'
102
+ | '/api/auth/$'
103
+ id:
104
+ | '__root__'
105
+ | '/'
106
+ | '/dashboard'
107
+ | '/forgot-password'
108
+ | '/reset-password'
109
+ | '/sign-in'
110
+ | '/sign-up'
111
+ | '/api/auth/$'
72
112
  fileRoutesById: FileRoutesById
73
113
  }
74
114
  export interface RootRouteChildren {
75
115
  IndexRoute: typeof IndexRoute
76
116
  DashboardRoute: typeof DashboardRoute
117
+ ForgotPasswordRoute: typeof ForgotPasswordRoute
118
+ ResetPasswordRoute: typeof ResetPasswordRoute
77
119
  SignInRoute: typeof SignInRoute
78
120
  SignUpRoute: typeof SignUpRoute
79
121
  ApiAuthSplatRoute: typeof ApiAuthSplatRoute
@@ -95,6 +137,20 @@ declare module '@tanstack/react-router' {
95
137
  preLoaderRoute: typeof DashboardRouteImport
96
138
  parentRoute: typeof rootRouteImport
97
139
  }
140
+ '/forgot-password': {
141
+ id: '/forgot-password'
142
+ path: '/forgot-password'
143
+ fullPath: '/forgot-password'
144
+ preLoaderRoute: typeof ForgotPasswordRouteImport
145
+ parentRoute: typeof rootRouteImport
146
+ }
147
+ '/reset-password': {
148
+ id: '/reset-password'
149
+ path: '/reset-password'
150
+ fullPath: '/reset-password'
151
+ preLoaderRoute: typeof ResetPasswordRouteImport
152
+ parentRoute: typeof rootRouteImport
153
+ }
98
154
  '/sign-in': {
99
155
  id: '/sign-in'
100
156
  path: '/sign-in'
@@ -122,6 +178,8 @@ declare module '@tanstack/react-router' {
122
178
  const rootRouteChildren: RootRouteChildren = {
123
179
  IndexRoute: IndexRoute,
124
180
  DashboardRoute: DashboardRoute,
181
+ ForgotPasswordRoute: ForgotPasswordRoute,
182
+ ResetPasswordRoute: ResetPasswordRoute,
125
183
  SignInRoute: SignInRoute,
126
184
  SignUpRoute: SignUpRoute,
127
185
  ApiAuthSplatRoute: ApiAuthSplatRoute,
@@ -1,18 +1,20 @@
1
- import { createFileRoute, redirect } from "@tanstack/react-router";
2
- import { Link } from "@tanstack/react-router";
1
+ import { createFileRoute, Link, redirect } from "@tanstack/react-router";
3
2
  import { ArrowRight, ShieldCheck } from "lucide-react";
4
3
 
4
+ import { ChangePasswordForm } from "~/components/auth/change-password-form";
5
+ import { EmailVerificationCard } from "~/components/auth/email-verification-card";
5
6
  import { SignOutButton } from "~/components/auth/sign-out-button";
6
- import { buttonVariants } from "~/components/ui/button";
7
+ import { Badge } from "~/components/ui/badge";
8
+ import { Button } from "~/components/ui/button";
7
9
  import {
8
10
  Card,
9
11
  CardContent,
10
12
  CardDescription,
13
+ CardFooter,
11
14
  CardHeader,
12
15
  CardTitle,
13
16
  } from "~/components/ui/card";
14
17
  import { getSession } from "~/lib/auth-functions";
15
- import { cn } from "~/lib/utils";
16
18
 
17
19
  export const Route = createFileRoute("/dashboard")({
18
20
  beforeLoad: async () => {
@@ -31,40 +33,45 @@ function Dashboard() {
31
33
  const user = Route.useRouteContext({ select: (ctx) => ctx.user });
32
34
 
33
35
  return (
34
- <main className="min-h-screen bg-[linear-gradient(180deg,_#f8fafc_0%,_#eef2ff_100%)] px-6 py-16 sm:px-10">
35
- <div className="mx-auto max-w-5xl space-y-8">
36
- <header className="flex flex-col gap-6 rounded-[2rem] border border-white/70 bg-white/85 p-8 shadow-xl shadow-slate-200/60 backdrop-blur md:flex-row md:items-end md:justify-between">
37
- <div className="space-y-3">
38
- <span className="inline-flex items-center gap-2 rounded-full bg-emerald-50 px-3 py-1 text-xs font-medium uppercase tracking-[0.24em] text-emerald-700">
39
- <ShieldCheck className="size-4" />
36
+ <main className="min-h-svh bg-muted px-6 py-16 sm:px-10">
37
+ <div className="mx-auto flex max-w-5xl flex-col gap-8">
38
+ <header className="flex flex-col gap-6 md:flex-row md:items-end md:justify-between">
39
+ <div className="flex flex-col gap-3">
40
+ <Badge variant="secondary">
41
+ <ShieldCheck data-icon="inline-start" />
40
42
  Authenticated session
41
- </span>
42
- <div className="space-y-1">
43
- <h1 className="text-3xl font-semibold tracking-tight text-slate-950">
43
+ </Badge>
44
+ <div className="flex flex-col gap-1">
45
+ <h1 className="text-3xl font-semibold tracking-tight">
44
46
  Welcome {user.name}
45
47
  </h1>
46
- <p className="text-sm text-slate-600">{user.email}</p>
48
+ <p className="text-sm text-muted-foreground">{user.email}</p>
47
49
  </div>
48
50
  </div>
49
51
  <SignOutButton />
50
52
  </header>
51
53
 
52
54
  <section className="grid gap-5 md:grid-cols-2">
55
+ <EmailVerificationCard
56
+ email={user.email}
57
+ emailVerified={user.emailVerified}
58
+ />
59
+ <ChangePasswordForm />
53
60
  <Card>
54
61
  <CardHeader>
55
62
  <CardTitle>Protected route example</CardTitle>
56
63
  <CardDescription>
57
- This page verifies the session on the server before rendering any
58
- content.
64
+ This page verifies the session on the server before rendering
65
+ any content.
59
66
  </CardDescription>
60
67
  </CardHeader>
61
- <CardContent className="space-y-4 text-sm text-slate-600">
68
+ <CardContent className="flex flex-col gap-4 text-muted-foreground">
62
69
  <p>
63
70
  The route guard calls{" "}
64
- <code className="font-mono text-slate-900">getSession()</code> in
65
- <code className="font-mono text-slate-900"> beforeLoad</code>,
71
+ <code className="font-mono text-foreground">getSession()</code>{" "}
72
+ in <code className="font-mono text-foreground">beforeLoad</code>,
66
73
  which reads the cookie headers server-side via{" "}
67
- <code className="font-mono text-slate-900">
74
+ <code className="font-mono text-foreground">
68
75
  auth.api.getSession
69
76
  </code>{" "}
70
77
  on every render and navigation.
@@ -84,28 +91,29 @@ function Dashboard() {
84
91
  product.
85
92
  </CardDescription>
86
93
  </CardHeader>
87
- <CardContent className="space-y-3 text-sm text-slate-600">
94
+ <CardContent className="flex flex-col gap-3 text-muted-foreground">
88
95
  <p>
89
96
  Replace the demo dashboard with your first authenticated page.
90
97
  </p>
91
98
  <p>Extend the schema with profile or onboarding fields.</p>
92
99
  <p>
93
- Add provider-based auth or email verification later if needed.
100
+ Add a GitHub or Google client ID and secret to .env to turn on
101
+ social sign-in, and RESEND_API_KEY to send real emails.
94
102
  </p>
95
- <Link
96
- to="/"
97
- className={cn(
98
- buttonVariants({ variant: "outline" }),
99
- "w-fit gap-2"
100
- )}
103
+ </CardContent>
104
+ <CardFooter>
105
+ <Button
106
+ variant="outline"
107
+ nativeButton={false}
108
+ render={<Link to="/" />}
101
109
  >
102
110
  Back to home
103
- <ArrowRight className="size-4" />
104
- </Link>
105
- </CardContent>
111
+ <ArrowRight data-icon="inline-end" />
112
+ </Button>
113
+ </CardFooter>
106
114
  </Card>
107
115
  </section>
108
116
  </div>
109
117
  </main>
110
118
  );
111
- }
119
+ }
@@ -0,0 +1,17 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+
3
+ import { ForgotPasswordForm } from "~/components/auth/forgot-password-form";
4
+
5
+ export const Route = createFileRoute("/forgot-password")({
6
+ component: ForgotPasswordPage,
7
+ });
8
+
9
+ function ForgotPasswordPage() {
10
+ return (
11
+ <main className="flex min-h-svh items-center justify-center bg-muted p-6 md:p-10">
12
+ <div className="w-full max-w-md">
13
+ <ForgotPasswordForm />
14
+ </div>
15
+ </main>
16
+ );
17
+ }