wexts 2.0.7 β 2.0.9
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 +123 -237
- package/dist/chunk-63MTCWU2.mjs +361 -0
- package/dist/chunk-63MTCWU2.mjs.map +1 -0
- package/dist/chunk-67IJ6H4J.mjs +44 -0
- package/dist/chunk-67IJ6H4J.mjs.map +1 -0
- package/dist/chunk-7NSRDJ5C.mjs +1 -0
- package/dist/chunk-7NSRDJ5C.mjs.map +1 -0
- package/dist/chunk-ASDXAK6G.js +44 -0
- package/dist/chunk-ASDXAK6G.js.map +1 -0
- package/dist/chunk-CKZ4VSCB.mjs +18 -0
- package/dist/chunk-CKZ4VSCB.mjs.map +1 -0
- package/dist/chunk-DW6GOKMF.js +57 -0
- package/dist/chunk-DW6GOKMF.js.map +1 -0
- package/dist/chunk-GKVPGKAH.js +66 -0
- package/dist/chunk-GKVPGKAH.js.map +1 -0
- package/dist/chunk-HSFLZUJN.mjs +57 -0
- package/dist/chunk-HSFLZUJN.mjs.map +1 -0
- package/dist/chunk-HU63F22V.js +361 -0
- package/dist/chunk-HU63F22V.js.map +1 -0
- package/dist/chunk-JMBD6DOP.js +225 -0
- package/dist/chunk-JMBD6DOP.js.map +1 -0
- package/dist/chunk-K7EIJSYQ.js +1 -0
- package/dist/chunk-K7EIJSYQ.js.map +1 -0
- package/dist/chunk-OTBYRUBE.mjs +225 -0
- package/dist/chunk-OTBYRUBE.mjs.map +1 -0
- package/dist/chunk-WMHVXEYQ.mjs +66 -0
- package/dist/chunk-WMHVXEYQ.mjs.map +1 -0
- package/dist/cli/index.js +156 -25
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +140 -7
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/index.mjs +2 -2
- package/dist/codegen/index.d.mts +1 -0
- package/dist/codegen/index.d.ts +1 -0
- package/dist/codegen/index.js +13 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/index.mjs +13 -0
- package/dist/codegen/index.mjs.map +1 -0
- package/dist/dev-server/index.d.mts +1 -0
- package/dist/dev-server/index.d.ts +1 -0
- package/dist/dev-server/index.js +13 -0
- package/dist/dev-server/index.js.map +1 -0
- package/dist/dev-server/index.mjs +13 -0
- package/dist/dev-server/index.mjs.map +1 -0
- package/dist/index-SjUaHgFr.d.mts +75 -0
- package/dist/index-SjUaHgFr.d.ts +75 -0
- package/dist/index-tFGPFVfQ.d.mts +67 -0
- package/dist/index-tFGPFVfQ.d.ts +67 -0
- package/dist/index.d.mts +83 -164
- package/dist/index.d.ts +83 -164
- package/dist/index.js +89 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -9
- package/dist/index.mjs.map +1 -1
- package/dist/nest/index.js +2 -2
- package/dist/nest/index.mjs +2 -2
- package/dist/next/index.d.mts +61 -3
- package/dist/next/index.d.ts +61 -3
- package/dist/next/index.js +140 -7
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +102 -7
- package/dist/next/index.mjs.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.mjs +2 -1
- package/package.json +2 -2
- package/templates/nestjs-api/.env +4 -0
- package/templates/nestjs-api/.env.example +1 -2
- package/templates/nestjs-api/package-lock.json +5623 -0
- package/templates/nestjs-api/package.json +21 -19
- package/templates/nestjs-api/prisma/dev.db +0 -0
- package/templates/nestjs-api/prisma/migrations/20251123205437_init/migration.sql +24 -0
- package/templates/nestjs-api/prisma/migrations/migration_lock.toml +3 -0
- package/templates/nestjs-api/src/auth/auth.controller.ts +5 -5
- package/templates/nestjs-api/src/main.ts +1 -1
- package/templates/nestjs-api/src/todos/todos.controller.ts +7 -7
- package/templates/nestjs-api/src/users/users.controller.ts +3 -3
- package/templates/nestjs-api/tsconfig.json +20 -1
- package/templates/nextjs-web/app/actions/auth.ts +79 -0
- package/templates/nextjs-web/app/dashboard/error.tsx +39 -0
- package/templates/nextjs-web/app/dashboard/loading.tsx +14 -0
- package/templates/nextjs-web/app/dashboard/page.tsx +2 -172
- package/templates/nextjs-web/app/globals.css +80 -15
- package/templates/nextjs-web/app/layout.tsx +7 -5
- package/templates/nextjs-web/app/login/page.tsx +2 -104
- package/templates/nextjs-web/app/page.tsx +1 -1
- package/templates/nextjs-web/app/register/page.tsx +2 -127
- package/templates/nextjs-web/components/ui/button.tsx +56 -0
- package/templates/nextjs-web/components/ui/card.tsx +79 -0
- package/templates/nextjs-web/components/ui/input.tsx +25 -0
- package/templates/nextjs-web/components/ui/label.tsx +24 -0
- package/templates/nextjs-web/features/auth/LoginForm.tsx +140 -0
- package/templates/nextjs-web/features/auth/RegisterForm.tsx +159 -0
- package/templates/nextjs-web/features/auth/api.ts +35 -0
- package/templates/nextjs-web/features/auth/index.ts +3 -0
- package/templates/nextjs-web/features/dashboard/DashboardView.tsx +204 -0
- package/templates/nextjs-web/features/dashboard/api.ts +9 -0
- package/templates/nextjs-web/features/dashboard/components.tsx +74 -0
- package/templates/nextjs-web/features/dashboard/index.ts +3 -0
- package/templates/nextjs-web/hooks/index.ts +4 -0
- package/templates/nextjs-web/lib/api-client.ts +89 -0
- package/templates/nextjs-web/lib/axios-global-config.ts +17 -0
- package/templates/nextjs-web/lib/utils.ts +6 -0
- package/templates/nextjs-web/lib/wexts-client.ts +4 -0
- package/templates/nextjs-web/next-env.d.ts +6 -0
- package/templates/nextjs-web/next.config.ts +20 -0
- package/templates/nextjs-web/package-lock.json +3254 -0
- package/templates/nextjs-web/package.json +23 -14
- package/templates/nextjs-web/postcss.config.js +6 -0
- package/templates/nextjs-web/tailwind.config.ts +55 -1
- package/templates/nextjs-web/tsconfig.json +41 -39
- package/templates/nextjs-web/next.config.mjs +0 -4
- /package/templates/nextjs-web/{.env.local.example β .env} +0 -0
package/README.md
CHANGED
|
@@ -4,39 +4,37 @@
|
|
|
4
4
|

|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
**Wexts v2** is a modern, production
|
|
7
|
+
**Wexts v2** is a modern, productionβready fullβstack framework that seamlessly integrates **NestJS 11** and **Next.js 16**. Build typeβsafe applications with automatic API client generation, shared types, and an exceptional developer experience.
|
|
8
8
|
|
|
9
9
|
> **Requirements:** Node.js 20.9.0+, PNPM 10.0.0+
|
|
10
10
|
|
|
11
11
|
## β¨ What's New in v2
|
|
12
12
|
|
|
13
13
|
- π― **Next.js 16** with Turbopack (stable) and React Compiler
|
|
14
|
-
- π **NestJS 11** with latest architectural improvements
|
|
14
|
+
- π **NestJS 11** with latest architectural improvements
|
|
15
15
|
- β‘ **TypeScript 5.9** with enhanced type inference
|
|
16
16
|
- π¦ **Modern Build System** with optimized bundling
|
|
17
17
|
- π₯ **React 19** full support
|
|
18
18
|
|
|
19
19
|
## π Features
|
|
20
20
|
|
|
21
|
-
- **π NestJS + Next.js Integration
|
|
22
|
-
- **π¦ All
|
|
23
|
-
- **π― Type
|
|
24
|
-
- **π οΈ CLI Tools
|
|
25
|
-
- **β‘ Auto API Client
|
|
26
|
-
- **π Auth Built
|
|
27
|
-
- **π Configuration Management
|
|
28
|
-
- **π¨ React Hooks
|
|
21
|
+
- **π NestJS + Next.js Integration** β seamless backendβfrontend connection
|
|
22
|
+
- **π¦ AllβinβOne SDK** β core utilities, HTTP client, decorators, and hooks in one package
|
|
23
|
+
- **π― TypeβSafe** β endβtoβend TypeScript from database to UI
|
|
24
|
+
- **π οΈ CLI Tools** β scaffold projects, generate code, manage development
|
|
25
|
+
- **β‘ Auto API Client** β generate typeβsafe clients from NestJS controllers
|
|
26
|
+
- **π Auth Builtβin** β readyβtoβuse authentication hooks for Next.js
|
|
27
|
+
- **π Configuration Management** β environmentβaware config loader
|
|
28
|
+
- **π¨ React Hooks** β `useWexts()`, `useAuth()` for seamless API integration
|
|
29
29
|
|
|
30
30
|
---
|
|
31
31
|
|
|
32
32
|
## π¦ Installation
|
|
33
33
|
|
|
34
|
-
### Global CLI
|
|
34
|
+
### Global CLI (run without installing globally)
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
|
|
38
|
-
# or
|
|
39
|
-
yarn global add wexts
|
|
37
|
+
npx wexts
|
|
40
38
|
```
|
|
41
39
|
|
|
42
40
|
### Project Dependency
|
|
@@ -54,16 +52,16 @@ yarn add wexts
|
|
|
54
52
|
### Create New Project
|
|
55
53
|
|
|
56
54
|
```bash
|
|
57
|
-
|
|
55
|
+
npx wexts create my-app --template monorepo
|
|
58
56
|
cd my-app
|
|
59
|
-
|
|
57
|
+
pnpm dev
|
|
60
58
|
```
|
|
61
59
|
|
|
62
60
|
This creates:
|
|
63
|
-
- `apps/api/`
|
|
64
|
-
- `apps/web/`
|
|
65
|
-
- `packages/types/`
|
|
66
|
-
- `packages/api-client/`
|
|
61
|
+
- `apps/api/` β NestJS 11 backend
|
|
62
|
+
- `apps/web/` β Next.js 16 frontend
|
|
63
|
+
- `packages/types/` β shared TypeScript definitions
|
|
64
|
+
- `packages/api-client/` β autoβgenerated SDK
|
|
67
65
|
|
|
68
66
|
---
|
|
69
67
|
|
|
@@ -73,24 +71,24 @@ This creates:
|
|
|
73
71
|
|
|
74
72
|
```typescript
|
|
75
73
|
import { Controller, Get, Post, Body } from '@nestjs/common';
|
|
76
|
-
import {
|
|
74
|
+
import { WextsController, WextsGet, WextsPost } from 'wexts/nest';
|
|
77
75
|
|
|
78
|
-
@
|
|
76
|
+
@WextsController('users')
|
|
79
77
|
@Controller('users')
|
|
80
78
|
export class UsersController {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
@WextsGet()
|
|
80
|
+
async findAll() {
|
|
81
|
+
return this.usersService.findAll();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@WextsPost()
|
|
85
|
+
async create(@Body() createUserDto: CreateUserDto) {
|
|
86
|
+
return this.usersService.create(createUserDto);
|
|
87
|
+
}
|
|
90
88
|
}
|
|
91
89
|
```
|
|
92
90
|
|
|
93
|
-
**Benefits**: The
|
|
91
|
+
**Benefits**: The `WextsController` and `WextsRoute` decorators add metadata for automatic API client generation.
|
|
94
92
|
|
|
95
93
|
---
|
|
96
94
|
|
|
@@ -100,18 +98,18 @@ export class UsersController {
|
|
|
100
98
|
|
|
101
99
|
```tsx
|
|
102
100
|
// app/layout.tsx
|
|
103
|
-
import {
|
|
104
|
-
|
|
105
|
-
export default function RootLayout({ children }) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
import { WextsProvider } from 'wexts/next';
|
|
102
|
+
|
|
103
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
104
|
+
return (
|
|
105
|
+
<html lang="en">
|
|
106
|
+
<body>
|
|
107
|
+
<WextsProvider baseUrl={process.env.NEXT_PUBLIC_API_URL || '/api'}>
|
|
108
|
+
{children}
|
|
109
|
+
</WextsProvider>
|
|
110
|
+
</body>
|
|
111
|
+
</html>
|
|
112
|
+
);
|
|
115
113
|
}
|
|
116
114
|
```
|
|
117
115
|
|
|
@@ -119,26 +117,28 @@ export default function RootLayout({ children }) {
|
|
|
119
117
|
|
|
120
118
|
```tsx
|
|
121
119
|
'use client';
|
|
122
|
-
import {
|
|
120
|
+
import { useWexts, useAuth } from 'wexts/next';
|
|
123
121
|
import { useEffect, useState } from 'react';
|
|
124
122
|
|
|
125
123
|
export default function UsersPage() {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
124
|
+
const { client } = useWexts();
|
|
125
|
+
const { user, isAuthenticated } = useAuth();
|
|
126
|
+
const [users, setUsers] = useState([]);
|
|
127
|
+
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
client.get<User[]>('/users').then(setUsers);
|
|
130
|
+
}, []);
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div>
|
|
134
|
+
{isAuthenticated && <p>Welcome, {user.name}!</p>}
|
|
135
|
+
<ul>
|
|
136
|
+
{users.map(u => (
|
|
137
|
+
<li key={u.id}>{u.name}</li>
|
|
138
|
+
))}
|
|
139
|
+
</ul>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
142
|
}
|
|
143
143
|
```
|
|
144
144
|
|
|
@@ -153,23 +153,23 @@ import { apiFetcher } from 'wexts/client';
|
|
|
153
153
|
const users = await apiFetcher.get<User[]>('/users');
|
|
154
154
|
|
|
155
155
|
// POST request
|
|
156
|
-
const newUser = await apiFetcher.post('/users', {
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
const newUser = await apiFetcher.post('/users', {
|
|
157
|
+
name: 'John',
|
|
158
|
+
email: 'john@example.com',
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
// Automatic Bearer token from localStorage
|
|
162
|
-
// Token stored as '
|
|
162
|
+
// Token stored as 'wexts_token'
|
|
163
163
|
```
|
|
164
164
|
|
|
165
165
|
---
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
## βοΈ Configuration
|
|
168
168
|
|
|
169
169
|
```typescript
|
|
170
170
|
import { config } from 'wexts';
|
|
171
171
|
|
|
172
|
-
// Load from
|
|
172
|
+
// Load from wexts.config.json or environment variables
|
|
173
173
|
const dbUrl = config.load('database');
|
|
174
174
|
const apiKey = config.load('apiKey', 'default-key');
|
|
175
175
|
|
|
@@ -177,25 +177,25 @@ const apiKey = config.load('apiKey', 'default-key');
|
|
|
177
177
|
config.set('feature_flags', { newUI: true });
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
### Logging
|
|
180
|
+
Create `wexts.config.json` in your project root:
|
|
183
181
|
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"database": "postgresql://localhost/mydb",
|
|
185
|
+
"apiPort": 5050,
|
|
186
|
+
"webPort": 3000,
|
|
187
|
+
"jwt": {
|
|
188
|
+
"secret": "your-secret-key",
|
|
189
|
+
"expiresIn": "7d"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
```
|
|
190
193
|
|
|
191
|
-
|
|
192
|
-
const apiLogger = createLogger({
|
|
193
|
-
prefix: '[API]',
|
|
194
|
-
level: LogLevel.DEBUG,
|
|
195
|
-
timestamp: true
|
|
196
|
-
});
|
|
194
|
+
**Environment Variables**: Prefix with `WEXTS_`
|
|
197
195
|
|
|
198
|
-
|
|
196
|
+
```bash
|
|
197
|
+
WEXTS_DATABASE=postgresql://localhost/mydb
|
|
198
|
+
WEXTS_JWT__SECRET=your-secret-key
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
---
|
|
@@ -204,17 +204,19 @@ apiLogger.debug('Detailed debug info');
|
|
|
204
204
|
|
|
205
205
|
```bash
|
|
206
206
|
# Create new project
|
|
207
|
-
|
|
207
|
+
wexts create <name> [--template monorepo|api|web]
|
|
208
208
|
|
|
209
209
|
# Start development servers
|
|
210
|
-
|
|
210
|
+
wexts dev [--port <port>]
|
|
211
211
|
|
|
212
212
|
# Build for production
|
|
213
|
-
|
|
213
|
+
wexts build
|
|
214
214
|
|
|
215
215
|
# Generate code
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
wexts generate controller <name>
|
|
217
|
+
|
|
218
|
+
# Shortcut for generate
|
|
219
|
+
wexts g module <name>
|
|
218
220
|
```
|
|
219
221
|
|
|
220
222
|
---
|
|
@@ -223,60 +225,47 @@ fusion g module <name>
|
|
|
223
225
|
|
|
224
226
|
### Core Modules
|
|
225
227
|
|
|
226
|
-
#### `wexts` (Main)
|
|
227
|
-
|
|
228
228
|
```typescript
|
|
229
229
|
import { Core, Config, Insight, Nest, Next } from 'wexts';
|
|
230
230
|
```
|
|
231
231
|
|
|
232
|
-
-
|
|
233
|
-
-
|
|
234
|
-
-
|
|
235
|
-
-
|
|
236
|
-
-
|
|
232
|
+
- **Core** β process management, filesystem utilities
|
|
233
|
+
- **Config** β configuration loader
|
|
234
|
+
- **Insight** β logging and metrics
|
|
235
|
+
- **Nest** β NestJS decorators and helpers
|
|
236
|
+
- **Next** β Next.js providers and hooks
|
|
237
237
|
|
|
238
|
-
|
|
238
|
+
### `wexts/client`
|
|
239
239
|
|
|
240
240
|
```typescript
|
|
241
|
-
import {
|
|
241
|
+
import { WextsFetcher, apiFetcher } from 'wexts/client';
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
-
-
|
|
245
|
-
-
|
|
244
|
+
- **WextsFetcher** β HTTP client class
|
|
245
|
+
- **apiFetcher** β singleton instance
|
|
246
246
|
|
|
247
|
-
|
|
247
|
+
### `wexts/nest`
|
|
248
248
|
|
|
249
249
|
```typescript
|
|
250
|
-
import {
|
|
251
|
-
FusionController,
|
|
252
|
-
FusionGet,
|
|
253
|
-
FusionPost,
|
|
254
|
-
FusionPut,
|
|
255
|
-
FusionDelete
|
|
256
|
-
} from 'wexts/nest';
|
|
250
|
+
import { WextsController, WextsGet, WextsPost, WextsPut, WextsDelete } from 'wexts/nest';
|
|
257
251
|
```
|
|
258
252
|
|
|
259
|
-
- NestJS decorators for API codegen
|
|
260
|
-
- Works alongside standard `@nestjs/common` decorators
|
|
253
|
+
- NestJS decorators for API codegen (works alongside standard `@nestjs/common` decorators)
|
|
261
254
|
|
|
262
|
-
|
|
255
|
+
### `wexts/next`
|
|
263
256
|
|
|
264
257
|
```typescript
|
|
265
|
-
import {
|
|
266
|
-
FusionProvider,
|
|
267
|
-
useFusion,
|
|
268
|
-
useAuth
|
|
269
|
-
} from 'wexts/next';
|
|
258
|
+
import { WextsProvider, useWexts, useAuth } from 'wexts/next';
|
|
270
259
|
```
|
|
271
260
|
|
|
272
|
-
-
|
|
273
|
-
-
|
|
274
|
-
-
|
|
261
|
+
- **WextsProvider** β React context provider for API client
|
|
262
|
+
- **useWexts()** β access API client in components
|
|
263
|
+
- **useAuth()** β authentication state management
|
|
275
264
|
|
|
276
|
-
|
|
265
|
+
### `wexts/types`
|
|
277
266
|
|
|
278
267
|
```typescript
|
|
279
|
-
import type { User, ApiResponse,
|
|
268
|
+
import type { User, ApiResponse, WextsConfig } from 'wexts/types';
|
|
280
269
|
```
|
|
281
270
|
|
|
282
271
|
- Shared TypeScript type definitions
|
|
@@ -285,124 +274,21 @@ import type { User, ApiResponse, FusionConfig } from 'wexts/types';
|
|
|
285
274
|
|
|
286
275
|
## ποΈ Project Structure
|
|
287
276
|
|
|
288
|
-
When you create a
|
|
277
|
+
When you create a project with `wexts create`, you get:
|
|
289
278
|
|
|
290
|
-
```
|
|
279
|
+
```text
|
|
291
280
|
my-app/
|
|
292
|
-
βββ apps/
|
|
293
|
-
β βββ api/
|
|
294
|
-
β β
|
|
295
|
-
β
|
|
296
|
-
β
|
|
297
|
-
|
|
298
|
-
β
|
|
299
|
-
β
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
β βββ app/
|
|
304
|
-
β β βββ layout.tsx
|
|
305
|
-
β β βββ page.tsx
|
|
306
|
-
β β βββ users/
|
|
307
|
-
β β βββ page.tsx
|
|
308
|
-
β βββ package.json
|
|
309
|
-
β
|
|
310
|
-
βββ packages/
|
|
311
|
-
β βββ types/ # Shared DTOs
|
|
312
|
-
β β βββ src/
|
|
313
|
-
β β βββ user.ts
|
|
314
|
-
β β βββ index.ts
|
|
315
|
-
β β
|
|
316
|
-
β βββ api-client/ # Auto-generated SDK
|
|
317
|
-
β βββ src/
|
|
318
|
-
β βββ index.ts
|
|
319
|
-
β
|
|
320
|
-
βββ turbo.json # TurboRepo config
|
|
321
|
-
βββ package.json # Root package
|
|
322
|
-
βββ fusion.config.json # Fusion configuration
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
---
|
|
326
|
-
|
|
327
|
-
## βοΈ Configuration
|
|
328
|
-
|
|
329
|
-
Create `fusion.config.json` in your project root:
|
|
330
|
-
|
|
331
|
-
```json
|
|
332
|
-
{
|
|
333
|
-
"database": "postgresql://localhost/mydb",
|
|
334
|
-
"apiPort": 5050,
|
|
335
|
-
"webPort": 3000,
|
|
336
|
-
"jwt": {
|
|
337
|
-
"secret": "your-secret-key",
|
|
338
|
-
"expiresIn": "7d"
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
Access via:
|
|
344
|
-
|
|
345
|
-
```typescript
|
|
346
|
-
import { config } from 'wexts';
|
|
347
|
-
|
|
348
|
-
const dbUrl = config.load('database');
|
|
349
|
-
const jwtConfig = config.load('jwt');
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
**Environment Variables**: Prefix with `FUSION_`
|
|
353
|
-
|
|
354
|
-
```bash
|
|
355
|
-
FUSION_DATABASE=postgresql://localhost/mydb
|
|
356
|
-
FUSION_JWT__SECRET=your-secret-key
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
---
|
|
360
|
-
|
|
361
|
-
## π Authentication Example
|
|
362
|
-
|
|
363
|
-
### Backend (NestJS)
|
|
364
|
-
|
|
365
|
-
```typescript
|
|
366
|
-
import { Controller, Post, Body } from '@nestjs/common';
|
|
367
|
-
import { FusionPost } from 'wexts/nest';
|
|
368
|
-
|
|
369
|
-
@Controller('auth')
|
|
370
|
-
export class AuthController {
|
|
371
|
-
@FusionPost()
|
|
372
|
-
@Post('login')
|
|
373
|
-
async login(@Body() credentials: LoginDto) {
|
|
374
|
-
const token = await this.authService.validateUser(credentials);
|
|
375
|
-
return { token, user: { id: 1, email: credentials.email } };
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
### Frontend (Next.js)
|
|
381
|
-
|
|
382
|
-
```tsx
|
|
383
|
-
'use client';
|
|
384
|
-
import { useAuth } from 'wexts/next';
|
|
385
|
-
|
|
386
|
-
export default function LoginPage() {
|
|
387
|
-
const { login, user, isAuthenticated, loading } = useAuth();
|
|
388
|
-
|
|
389
|
-
const handleLogin = async (e: FormEvent) => {
|
|
390
|
-
e.preventDefault();
|
|
391
|
-
await login('user@example.com', 'password');
|
|
392
|
-
// Automatically redirects or updates UI
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
if (loading) return <p>Loading...</p>;
|
|
396
|
-
if (isAuthenticated) return <p>Welcome, {user.name}!</p>;
|
|
397
|
-
|
|
398
|
-
return (
|
|
399
|
-
<form onSubmit={handleLogin}>
|
|
400
|
-
<input type="email" required />
|
|
401
|
-
<input type="password" required />
|
|
402
|
-
<button type="submit">Login</button>
|
|
403
|
-
</form>
|
|
404
|
-
);
|
|
405
|
-
}
|
|
281
|
+
βββ apps/
|
|
282
|
+
β βββ api/ # NestJS 11 backend
|
|
283
|
+
β β βββ src/
|
|
284
|
+
β βββ web/ # Next.js 16 frontend
|
|
285
|
+
β βββ app/
|
|
286
|
+
βββ packages/
|
|
287
|
+
β βββ types/ # Shared DTOs
|
|
288
|
+
β βββ api-client/ # Autoβgenerated SDK
|
|
289
|
+
βββ turbo.json
|
|
290
|
+
βββ package.json
|
|
291
|
+
βββ wexts.config.json
|
|
406
292
|
```
|
|
407
293
|
|
|
408
294
|
---
|
|
@@ -412,7 +298,7 @@ export default function LoginPage() {
|
|
|
412
298
|
### Build
|
|
413
299
|
|
|
414
300
|
```bash
|
|
415
|
-
|
|
301
|
+
wexts build
|
|
416
302
|
```
|
|
417
303
|
|
|
418
304
|
### Deploy API (NestJS)
|