nextworks 0.1.0-alpha.13 → 0.1.0-alpha.14
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 +20 -9
- package/dist/kits/auth-core/.nextworks/docs/AUTH_CORE_README.md +2 -2
- package/dist/kits/auth-core/.nextworks/docs/AUTH_QUICKSTART.md +264 -244
- package/dist/kits/auth-core/app/(protected)/settings/profile/profile-form.tsx +120 -114
- package/dist/kits/auth-core/app/api/auth/forgot-password/route.ts +116 -114
- package/dist/kits/auth-core/app/api/auth/reset-password/route.ts +66 -63
- package/dist/kits/auth-core/app/api/auth/send-verify-email/route.ts +1 -1
- package/dist/kits/auth-core/app/api/users/[id]/route.ts +134 -127
- package/dist/kits/auth-core/app/auth/reset-password/page.tsx +186 -187
- package/dist/kits/auth-core/components/auth/dashboard.tsx +25 -2
- package/dist/kits/auth-core/components/auth/forgot-password-form.tsx +90 -90
- package/dist/kits/auth-core/components/auth/login-form.tsx +492 -467
- package/dist/kits/auth-core/components/auth/signup-form.tsx +28 -29
- package/dist/kits/auth-core/lib/auth.ts +46 -15
- package/dist/kits/auth-core/lib/forms/map-errors.ts +37 -11
- package/dist/kits/auth-core/lib/server/result.ts +45 -45
- package/dist/kits/auth-core/lib/validation/forms.ts +1 -2
- package/dist/kits/auth-core/package-deps.json +1 -1
- package/dist/kits/auth-core/types/next-auth.d.ts +1 -1
- package/dist/kits/blocks/.nextworks/docs/BLOCKS_QUICKSTART.md +2 -8
- package/dist/kits/blocks/.nextworks/docs/THEME_GUIDE.md +18 -1
- package/dist/kits/blocks/app/templates/productlaunch/page.tsx +0 -2
- package/dist/kits/blocks/components/sections/FAQ.tsx +0 -1
- package/dist/kits/blocks/components/sections/Newsletter.tsx +2 -2
- package/dist/kits/blocks/components/ui/switch.tsx +78 -78
- package/dist/kits/blocks/package-deps.json +3 -3
- package/dist/kits/data/.nextworks/docs/DATA_QUICKSTART.md +128 -112
- package/dist/kits/data/.nextworks/docs/DATA_README.md +2 -1
- package/dist/kits/data/app/api/posts/[id]/route.ts +83 -83
- package/dist/kits/data/app/api/posts/route.ts +136 -138
- package/dist/kits/data/app/api/seed-demo/route.ts +1 -2
- package/dist/kits/data/app/api/users/[id]/route.ts +29 -17
- package/dist/kits/data/app/api/users/check-email/route.ts +1 -1
- package/dist/kits/data/app/api/users/check-unique/route.ts +30 -27
- package/dist/kits/data/app/api/users/route.ts +0 -2
- package/dist/kits/data/app/examples/demo/create-post-form.tsx +108 -106
- package/dist/kits/data/app/examples/demo/page.tsx +2 -1
- package/dist/kits/data/app/examples/demo/seed-demo-button.tsx +1 -1
- package/dist/kits/data/components/admin/posts-manager.tsx +727 -719
- package/dist/kits/data/components/admin/users-manager.tsx +435 -432
- package/dist/kits/data/lib/server/result.ts +5 -2
- package/dist/kits/data/package-deps.json +1 -1
- package/dist/kits/data/scripts/seed-demo.mjs +1 -2
- package/dist/kits/forms/app/api/wizard/route.ts +76 -71
- package/dist/kits/forms/app/examples/forms/server-action/page.tsx +78 -71
- package/dist/kits/forms/components/hooks/useCheckUnique.ts +85 -79
- package/dist/kits/forms/components/ui/form/form-control.tsx +28 -28
- package/dist/kits/forms/components/ui/form/form-description.tsx +23 -22
- package/dist/kits/forms/components/ui/form/form-item.tsx +21 -21
- package/dist/kits/forms/components/ui/form/form-label.tsx +24 -24
- package/dist/kits/forms/components/ui/form/form-message.tsx +28 -29
- package/dist/kits/forms/components/ui/switch.tsx +78 -78
- package/dist/kits/forms/lib/forms/map-errors.ts +1 -1
- package/dist/kits/forms/lib/validation/forms.ts +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,13 +9,24 @@ Nextworks is a CLI that installs **modular Next.js building blocks** into your a
|
|
|
9
9
|
|
|
10
10
|
> **Status:** early‑access alpha. Expect rough edges and breaking changes between alpha releases.
|
|
11
11
|
>
|
|
12
|
-
> In this alpha, the most reliable setup is
|
|
12
|
+
> In this alpha, the most reliable setup is:
|
|
13
13
|
>
|
|
14
|
-
>
|
|
15
|
-
>
|
|
16
|
-
>
|
|
14
|
+
> 1. Install the CLI (as a dev dependency) and install dependencies:
|
|
15
|
+
>
|
|
16
|
+
> ```bash
|
|
17
|
+
> npm install -D nextworks
|
|
18
|
+
> npm install
|
|
19
|
+
> ```
|
|
20
|
+
>
|
|
21
|
+
> 2. Install **Blocks** first:
|
|
22
|
+
>
|
|
23
|
+
> ```bash
|
|
24
|
+
> npx nextworks add blocks --sections --templates
|
|
25
|
+
> ```
|
|
26
|
+
>
|
|
27
|
+
> 3. Then add **Auth Core**, **Forms**, and **Data** on top.
|
|
17
28
|
>
|
|
18
|
-
>
|
|
29
|
+
> Partial setups (e.g. Auth/Data without Blocks) may require manual tweaks and are not yet fully supported.
|
|
19
30
|
|
|
20
31
|
---
|
|
21
32
|
|
|
@@ -112,10 +123,10 @@ Then:
|
|
|
112
123
|
NEXTAUTH_SECRET=your-strong-secret
|
|
113
124
|
```
|
|
114
125
|
|
|
115
|
-
2. Install
|
|
126
|
+
2. Install dependencies:
|
|
116
127
|
|
|
117
128
|
```bash
|
|
118
|
-
npm install
|
|
129
|
+
npm install
|
|
119
130
|
```
|
|
120
131
|
|
|
121
132
|
3. Run Prisma:
|
|
@@ -218,9 +229,9 @@ You can add a short “Nextworks setup” section to your app README:
|
|
|
218
229
|
|
|
219
230
|
Set DATABASE_URL, NEXTAUTH_URL, NEXTAUTH_SECRET (and any OAuth or email provider vars you need).
|
|
220
231
|
|
|
221
|
-
3. Install
|
|
232
|
+
3. Install dependencies and run migrations:
|
|
222
233
|
|
|
223
|
-
npm install
|
|
234
|
+
npm install
|
|
224
235
|
npx prisma generate
|
|
225
236
|
npx prisma migrate dev -n init
|
|
226
237
|
|
|
@@ -56,11 +56,11 @@ If you choose a different database provider, update the `provider` field in your
|
|
|
56
56
|
|
|
57
57
|
Environment variables
|
|
58
58
|
|
|
59
|
-
The kit relies on the following environment variables. Document these in post-install output or in your project's README
|
|
59
|
+
The kit relies on the following environment variables. Document these in post-install output or in your project's README.
|
|
60
60
|
|
|
61
61
|
Required (for core auth):
|
|
62
62
|
|
|
63
|
-
- DATABASE_URL
|
|
63
|
+
- DATABASE_URL (required by Prisma)
|
|
64
64
|
- NEXTAUTH_URL (e.g. http://localhost:3000)
|
|
65
65
|
- NEXTAUTH_SECRET
|
|
66
66
|
|
|
@@ -1,244 +1,264 @@
|
|
|
1
|
-
# Auth Quickstart
|
|
2
|
-
|
|
3
|
-
Follow these steps to get email/password auth (and optional GitHub OAuth) running in under 5 minutes.
|
|
4
|
-
|
|
5
|
-
If you are using the `nextworks` CLI in your own app, the recommended alpha setup is to install Blocks with sections and templates first, then Auth Core:
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npx nextworks add blocks --sections --templates
|
|
9
|
-
npx nextworks add auth-core
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Then follow the steps below inside your app.
|
|
13
|
-
|
|
14
|
-
## 1) Copy environment variables
|
|
15
|
-
|
|
16
|
-
Create a `.env` file based on `.env.example`:
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
cp .env.example .env
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Fill in values for the following environment variables used by the Auth kit:
|
|
23
|
-
|
|
24
|
-
- DATABASE_URL — PostgreSQL connection string
|
|
25
|
-
- NEXTAUTH_URL — URL of your app (e.g. http://localhost:3000 in dev)
|
|
26
|
-
- NEXTAUTH_SECRET — a strong random string (used to sign NextAuth tokens)
|
|
27
|
-
|
|
28
|
-
Optional / password reset / email provider vars:
|
|
29
|
-
|
|
30
|
-
- GITHUB_ID — (optional) GitHub OAuth client id
|
|
31
|
-
- GITHUB_SECRET — (optional) GitHub OAuth client secret
|
|
32
|
-
- NEXTWORKS_ENABLE_PASSWORD_RESET — set to `1` to enable the dev password reset scaffold (default: disabled)
|
|
33
|
-
- NEXTWORKS_USE_DEV_EMAIL — set to `1` to enable Ethereal dev email transport (for local testing only). **Works in `next dev` only.**
|
|
34
|
-
- SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, NOREPLY_EMAIL — when using a real SMTP provider (**required in production** when password reset is enabled). If not configured, `/api/auth/forgot-password` returns **404 by design**.
|
|
35
|
-
- NODE_ENV — (production/dev) used to guard password-reset behavior
|
|
36
|
-
|
|
37
|
-
Notes:
|
|
38
|
-
|
|
39
|
-
- The Auth kit will only enable the GitHub provider when both GITHUB_ID and GITHUB_SECRET are present.
|
|
40
|
-
- Password reset remains disabled by default; enable cautiously and only after configuring a real mail provider in production.
|
|
41
|
-
|
|
42
|
-
## 2) Install and generate Prisma
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
If you
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
-
|
|
144
|
-
|
|
145
|
-
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
-
|
|
166
|
-
|
|
167
|
-
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
177
|
-
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
1
|
+
# Auth Quickstart
|
|
2
|
+
|
|
3
|
+
Follow these steps to get email/password auth (and optional GitHub OAuth) running in under 5 minutes.
|
|
4
|
+
|
|
5
|
+
If you are using the `nextworks` CLI in your own app, the recommended alpha setup is to install Blocks with sections and templates first, then Auth Core:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx nextworks add blocks --sections --templates
|
|
9
|
+
npx nextworks add auth-core
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Then follow the steps below inside your app.
|
|
13
|
+
|
|
14
|
+
## 1) Copy environment variables
|
|
15
|
+
|
|
16
|
+
Create a `.env` file based on `.env.example`:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
cp .env.example .env
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Fill in values for the following environment variables used by the Auth kit:
|
|
23
|
+
|
|
24
|
+
- DATABASE_URL — PostgreSQL connection string
|
|
25
|
+
- NEXTAUTH_URL — URL of your app (e.g. http://localhost:3000 in dev)
|
|
26
|
+
- NEXTAUTH_SECRET — a strong random string (used to sign NextAuth tokens)
|
|
27
|
+
|
|
28
|
+
Optional / password reset / email provider vars:
|
|
29
|
+
|
|
30
|
+
- GITHUB_ID — (optional) GitHub OAuth client id
|
|
31
|
+
- GITHUB_SECRET — (optional) GitHub OAuth client secret
|
|
32
|
+
- NEXTWORKS_ENABLE_PASSWORD_RESET — set to `1` to enable the dev password reset scaffold (default: disabled)
|
|
33
|
+
- NEXTWORKS_USE_DEV_EMAIL — set to `1` to enable Ethereal dev email transport (for local testing only). **Works in `next dev` only.**
|
|
34
|
+
- SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, NOREPLY_EMAIL — when using a real SMTP provider (**required in production** when password reset is enabled). If not configured, `/api/auth/forgot-password` returns **404 by design**.
|
|
35
|
+
- NODE_ENV — (production/dev) used to guard password-reset behavior
|
|
36
|
+
|
|
37
|
+
Notes:
|
|
38
|
+
|
|
39
|
+
- The Auth kit will only enable the GitHub provider when both GITHUB_ID and GITHUB_SECRET are present.
|
|
40
|
+
- Password reset remains disabled by default; enable cautiously and only after configuring a real mail provider in production.
|
|
41
|
+
|
|
42
|
+
## 2) Install and generate Prisma (required)
|
|
43
|
+
|
|
44
|
+
Auth Core requires Prisma (this kit is Prisma-coupled by design).
|
|
45
|
+
|
|
46
|
+
If you are using the monorepo directly:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install
|
|
50
|
+
npx prisma generate
|
|
51
|
+
npx prisma migrate dev -n init
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
If you installed Auth via the CLI (`npx nextworks add auth-core`):
|
|
55
|
+
|
|
56
|
+
- Prisma dependencies are added to your app via the kit's `package-deps.json` (so a plain `npm install` should be enough).
|
|
57
|
+
- You still must ensure `DATABASE_URL` is set, and you must run Prisma generate + migrations.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install
|
|
61
|
+
npx prisma generate
|
|
62
|
+
npx prisma migrate dev -n init
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This applies the Prisma schema and generates the Prisma client.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## 3) Start the dev server
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
npm run dev
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Windows + Prisma + Next 16 (Turbopack) note
|
|
75
|
+
|
|
76
|
+
If you are on **Windows** and have installed the **Auth Core** kit (which uses Prisma under the hood) on **Next 16+**, the Next dev server may need permission to create symlinks for the Prisma client. On Windows, this can cause errors like:
|
|
77
|
+
|
|
78
|
+
> `create symlink to ../../../../node_modules/@prisma/client`
|
|
79
|
+
> `Caused by: A required privilege is not held by the client. (os error 1314)`
|
|
80
|
+
|
|
81
|
+
If you see this (often surfaced as a 500 on `/api/auth/session` or a NextAuth `CLIENT_FETCH_ERROR`), do one of the following:
|
|
82
|
+
|
|
83
|
+
- **Recommended**: Enable **Developer Mode** in Windows (Settings → For developers → Developer mode). This allows symlinks in normal terminals.
|
|
84
|
+
- Or: Run your dev server from an **elevated PowerShell/terminal** ("Run as administrator").
|
|
85
|
+
|
|
86
|
+
After doing one of these, restart `npm run dev` and reload your app.
|
|
87
|
+
|
|
88
|
+
Visit:
|
|
89
|
+
|
|
90
|
+
- http://localhost:3000/auth/signup to create a user
|
|
91
|
+
- http://localhost:3000/auth/login to sign in
|
|
92
|
+
- http://localhost:3000/dashboard after login
|
|
93
|
+
|
|
94
|
+
## 4) Optional: GitHub OAuth
|
|
95
|
+
|
|
96
|
+
If you provided GITHUB_ID and GITHUB_SECRET in `.env`, the GitHub provider will be enabled and the GitHub button will appear on the forms. If not provided, the button will be hidden and only email/password is available.
|
|
97
|
+
|
|
98
|
+
## 5) Roles (optional)
|
|
99
|
+
|
|
100
|
+
The `User` model has a `role` field (default: `user`). Role is propagated to the JWT and session so you can gate pages/components. You can later add admin tooling or seed scripts as needed.
|
|
101
|
+
|
|
102
|
+
## 6) Seed and promote admin scripts
|
|
103
|
+
|
|
104
|
+
- `scripts/seed-demo.mjs` (already in the repo) creates a demo admin user and sample posts for quick demos.
|
|
105
|
+
- `scripts/promote-admin.mjs` (new) is idempotent and promotes an existing user to `admin`:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
node ./scripts/promote-admin.mjs admin@example.com
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 7) Forgot password (development scaffold)
|
|
112
|
+
|
|
113
|
+
This is a development scaffold that is disabled by default. To enable the password reset feature, set:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
NEXTWORKS_ENABLE_PASSWORD_RESET=1
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- POST `/api/auth/forgot-password` accepts `{ email }`. When enabled the endpoint generates a one-time token stored in the database and (in development) prints a reset link to the server console. The endpoint always returns a generic success message to avoid user enumeration.
|
|
120
|
+
- GET `/api/auth/reset-password?token=...` validates a token (only when enabled).
|
|
121
|
+
- POST `/api/auth/reset-password` accepts `{ token, password, confirmPassword }` and updates the user password while invalidating the token (only when enabled).
|
|
122
|
+
|
|
123
|
+
Security notes:
|
|
124
|
+
|
|
125
|
+
- The scaffold is intentionally disabled by default; enable it only for local testing or after hardening.
|
|
126
|
+
- The forgot-password scaffold uses an in-memory rate limiter for demo purposes — replace it with a centralized rate limiter (Redis, API gateway) in production.
|
|
127
|
+
- Always use a real email provider (SMTP, SendGrid, etc.) in production and never log reset tokens in server logs.
|
|
128
|
+
|
|
129
|
+
Migration & upgrade notes
|
|
130
|
+
|
|
131
|
+
- A recent schema migration changed PasswordReset to store tokenHash (SHA-256) instead of the raw token. Steps we executed:
|
|
132
|
+
1. Added `tokenHash` (nullable) to the PasswordReset model and made `token` nullable in Prisma.
|
|
133
|
+
2. Generated a migration that adds the tokenHash column and a unique index on it.
|
|
134
|
+
3. Ran a one-off script `scripts/populate-tokenhash.mjs` to compute SHA-256 hashes for previous tokens and fill `tokenHash`.
|
|
135
|
+
4. Applied the migration and regenerated the Prisma client (`npx prisma generate`).
|
|
136
|
+
|
|
137
|
+
- To enable password reset behavior in your environment, set:
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
NEXTWORKS_ENABLE_PASSWORD_RESET=1
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- Dev email helper (optional): there is an optional dev email helper (nodemailer + Ethereal) that can be enabled with `NEXTWORKS_USE_DEV_EMAIL=1`. When enabled (and NEXTWORKS_ENABLE_PASSWORD_RESET=1), forgot-password will send an Ethereal email and the server will log only the Ethereal preview URL (no plaintext token in logs). This helper is strictly opt-in for development only. Use a real email provider in production.
|
|
144
|
+
|
|
145
|
+
- Production hardening: Password reset should only be enabled in production when a mail provider is configured. To harden the scaffold in production, ensure the following environment variables are set for SMTP (or equivalent for other providers):
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
SMTP_HOST=smtp.example.com
|
|
149
|
+
SMTP_PORT=587
|
|
150
|
+
SMTP_USER=user@example.com
|
|
151
|
+
SMTP_PASS=supersecret
|
|
152
|
+
NOREPLY_EMAIL=no-reply@example.com
|
|
153
|
+
NEXTWORKS_ENABLE_PASSWORD_RESET=1
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
When NEXTWORKS_ENABLE_PASSWORD_RESET=1 and NODE_ENV=production the server will refuse to enable password reset unless a mail provider is configured. The server will not log reset tokens or URLs in production logs.
|
|
157
|
+
|
|
158
|
+
Security checklist before enabling reset in production:
|
|
159
|
+
|
|
160
|
+
- Set a strong NEXTAUTH_SECRET
|
|
161
|
+
- Use HTTPS/TLS
|
|
162
|
+
- Replace in-memory rate limiting with a centralized store (Redis/API Gateway)
|
|
163
|
+
- Configure and test a real mail provider (SMTP, SendGrid, etc.)
|
|
164
|
+
- Ensure password reset tokens are expired/cleaned up periodically
|
|
165
|
+
- Review logging to avoid token leakage
|
|
166
|
+
|
|
167
|
+
- Promotion script: to promote an existing user to admin, run:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
node ./scripts/promote-admin.mjs user@example.com
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- Important: Before turning password reset on in production, ensure you:
|
|
174
|
+
- Replace the in-memory rate limiter with a centralized solution (Redis or API Gateway).
|
|
175
|
+
- Configure a real email provider and remove console logging of tokens.
|
|
176
|
+
- Ensure tokens are cleaned up periodically (see scripts/prune-password-resets.mjs stub).
|
|
177
|
+
- Set a secure NEXTAUTH_SECRET and use HTTPS in production.
|
|
178
|
+
|
|
179
|
+
## Files & kit manifest (what to look at)
|
|
180
|
+
|
|
181
|
+
If you want to inspect or package the Auth kit, the primary files and routes are listed below. This is a minimal manifest intended for documentation and CLI packaging reference — adjust paths if you extract the kit into another project.
|
|
182
|
+
|
|
183
|
+
Key files
|
|
184
|
+
|
|
185
|
+
- NextAuth handler & callbacks: lib/auth.ts
|
|
186
|
+
- Prisma client: lib/prisma.ts
|
|
187
|
+
- Auth helper utilities: lib/auth-helpers.ts, lib/hash.ts
|
|
188
|
+
- Email providers: lib/email/index.ts, lib/email/dev-transport.ts, lib/email/provider-smtp.ts
|
|
189
|
+
- Validation helpers: lib/validation/forms.ts
|
|
190
|
+
- Form error mapping: lib/forms/map-errors.ts
|
|
191
|
+
- UI components used by Auth: components/auth/_ and components/ui/_ (login-form.tsx, signup-form.tsx, button/input/label etc.)
|
|
192
|
+
- Pages & API routes:
|
|
193
|
+
- app/auth/login/page.tsx
|
|
194
|
+
- app/auth/signup/page.tsx
|
|
195
|
+
- app/auth/forgot-password/page.tsx
|
|
196
|
+
- app/auth/reset-password/page.tsx
|
|
197
|
+
- app/auth/verify-email/page.tsx
|
|
198
|
+
- app/api/auth/[...nextauth]/route.ts
|
|
199
|
+
- app/api/auth/forgot-password/route.ts
|
|
200
|
+
- app/api/auth/reset-password/route.ts
|
|
201
|
+
- app/api/auth/send-verify-email/route.ts
|
|
202
|
+
- app/api/auth/providers/route.ts
|
|
203
|
+
- app/api/signup/route.ts
|
|
204
|
+
- Prisma schema & auth models: prisma/schema.prisma and prisma/auth-models.prisma
|
|
205
|
+
- Seed & maintenance scripts: scripts/seed-demo.mjs, scripts/promote-admin.mjs, scripts/populate-tokenhash.mjs
|
|
206
|
+
|
|
207
|
+
Minimal manifest (JSON)
|
|
208
|
+
|
|
209
|
+
{
|
|
210
|
+
"name": "auth-core",
|
|
211
|
+
"files": [
|
|
212
|
+
"lib/auth.ts",
|
|
213
|
+
"lib/prisma.ts",
|
|
214
|
+
"lib/auth-helpers.ts",
|
|
215
|
+
"lib/hash.ts",
|
|
216
|
+
"lib/forms/map-errors.ts",
|
|
217
|
+
"lib/validation/forms.ts",
|
|
218
|
+
"lib/email/index.ts",
|
|
219
|
+
"components/auth/login-form.tsx",
|
|
220
|
+
"components/auth/signup-form.tsx",
|
|
221
|
+
"components/auth/logout-button.tsx",
|
|
222
|
+
"components/session-provider.tsx",
|
|
223
|
+
"app/auth/login/page.tsx",
|
|
224
|
+
"app/auth/signup/page.tsx",
|
|
225
|
+
"app/api/auth/[...nextauth]/route.ts",
|
|
226
|
+
"app/api/signup/route.ts",
|
|
227
|
+
"prisma/schema.prisma",
|
|
228
|
+
"scripts/seed-demo.mjs",
|
|
229
|
+
"scripts/promote-admin.mjs"
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
## Where to customize NextAuth behavior
|
|
234
|
+
|
|
235
|
+
- The NextAuth configuration and handlers live in lib/auth.ts. Common customizations include:
|
|
236
|
+
- Adjusting providers (add/remove OAuth providers).
|
|
237
|
+
- Modifying session and jwt callbacks to include or remove fields on the token/session.
|
|
238
|
+
- Customizing pages (e.g., pages.signIn) or redirect logic.
|
|
239
|
+
|
|
240
|
+
- Notes: lib/auth.ts already persists user.id and role into the JWT and exposes them on session.user for server components. If you change what is exposed on the session, ensure server-side checks (RBAC) are updated accordingly.
|
|
241
|
+
|
|
242
|
+
## CLI kit source (if packaging later)
|
|
243
|
+
|
|
244
|
+
- A kit skeleton for packaging already exists in the repo at: `cli/kits/auth-core/` — it contains a compact copy of the core auth files (components, lib, prisma snippets) used by the CLI during development. Use that folder as a starting point when you implement the CLI packaging step.
|
|
245
|
+
|
|
246
|
+
## Post-install checklist (Auth)
|
|
247
|
+
|
|
248
|
+
1. Copy `.env.example` → `.env` and set DATABASE_URL, NEXTAUTH_URL, NEXTAUTH_SECRET (and GITHUB_ID/GITHUB_SECRET if using GitHub OAuth).
|
|
249
|
+
2. Generate Prisma client and run migrations:
|
|
250
|
+
|
|
251
|
+
npx prisma generate
|
|
252
|
+
npx prisma migrate dev -n init
|
|
253
|
+
|
|
254
|
+
3. (Optional) Seed demo data for quick testing:
|
|
255
|
+
|
|
256
|
+
SEED_ADMIN_EMAIL=admin@example.com SEED_ADMIN_PASSWORD=password123 node ./scripts/seed-demo.mjs
|
|
257
|
+
|
|
258
|
+
4. Start dev server:
|
|
259
|
+
|
|
260
|
+
npm run dev
|
|
261
|
+
|
|
262
|
+
5. Visit: `/auth/signup`, `/auth/login` and `/dashboard` for protected pages.
|
|
263
|
+
|
|
264
|
+
If you want, I can also create a short docs/AUTH_MANIFEST.json file containing the JSON manifest above in the repo (useful for CLI packaging). I will not create CLI code or copy files unless you ask.
|