Skip to content

Commit 9db746c

Browse files
committed
1.5.0: refactor API URL resolution to runtime-only config, add cookie Secure flag, and update deps
1 parent 18d483c commit 9db746c

File tree

8 files changed

+2196
-1495
lines changed

8 files changed

+2196
-1495
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,58 @@ npm install tus-js-client
4242
- **i18n Support** - English and German translations (works without i18n too)
4343
- **Auto-imports** - All composables and components are auto-imported
4444

45+
## Environment Variables
46+
47+
| Variable | Context | Description |
48+
|----------|---------|-------------|
49+
| `NUXT_PUBLIC_API_URL` | Client + Server | Public API URL. Primary way to configure the API endpoint. Used for client-side requests and as SSR fallback. |
50+
| `NUXT_API_URL` | Server only | Internal API URL for SSR requests. Use when the backend has a private network address that should not be exposed to the client. |
51+
| `NUXT_PUBLIC_API_PROXY` | Client | Set to `true` to enable the Vite dev proxy. Routes client requests through `/api/` for same-origin cookies. **Only for local development.** |
52+
53+
### How URL Resolution Works
54+
55+
All environment variables are resolved **at runtime** (not build time). This means you can build a Docker image once and deploy it to different environments by changing env vars — no rebuild needed.
56+
57+
**SSR fallback chain:**
58+
`NUXT_API_URL``NUXT_PUBLIC_API_URL``auth.baseURL` (from nuxt.config.ts) → `http://localhost:3000`
59+
60+
**Client fallback chain (no proxy):**
61+
`NUXT_PUBLIC_API_URL``auth.baseURL` (from nuxt.config.ts) → `http://localhost:3000`
62+
63+
**Client with proxy (`NUXT_PUBLIC_API_PROXY=true`):**
64+
All requests go to `/api/{path}` — the Vite dev proxy forwards them to the backend.
65+
66+
> **Security:** `NUXT_API_URL` is never exposed to the client bundle. It stays in `runtimeConfig.apiUrl` (server only). This is important when using internal network addresses like `http://api.svc.cluster.local`.
67+
68+
### Deployment Scenarios
69+
70+
**Local development** — Frontend and backend on different ports, proxy ensures same-origin cookies:
71+
```bash
72+
NUXT_PUBLIC_API_URL=http://localhost:3000
73+
NUXT_PUBLIC_API_PROXY=true
74+
```
75+
76+
**Production (simple)** — Backend reachable via public URL from both SSR and client:
77+
```bash
78+
NUXT_PUBLIC_API_URL=https://api.example.com
79+
```
80+
81+
**Production (internal network)** — SSR uses fast internal route, client uses public URL:
82+
```bash
83+
NUXT_PUBLIC_API_URL=https://api.example.com
84+
NUXT_API_URL=http://api-internal:3000
85+
```
86+
87+
**Legacy (nuxt.config.ts only)** — Works but env vars are preferred for runtime flexibility:
88+
```typescript
89+
// nuxt.config.ts
90+
ltExtensions: {
91+
auth: {
92+
baseURL: 'https://api.example.com',
93+
},
94+
}
95+
```
96+
4597
## Configuration
4698

4799
```typescript
@@ -53,7 +105,7 @@ export default defineNuxtConfig({
53105
// Auth configuration
54106
auth: {
55107
enabled: true, // Enable auth features
56-
baseURL: '', // API base URL (empty = use Nuxt proxy)
108+
baseURL: '', // API base URL (empty = use env vars)
57109
basePath: '/iam', // Better-Auth endpoint prefix
58110
loginPath: '/auth/login', // Login redirect path
59111
twoFactorRedirectPath: '/auth/2fa', // 2FA redirect path
@@ -68,6 +120,18 @@ export default defineNuxtConfig({
68120
enabled: true, // 401 auto-handler
69121
publicPaths: ['/auth/login', '/auth/register'],
70122
},
123+
124+
// System setup (first admin user creation)
125+
systemSetup: {
126+
enabled: false, // Enable setup flow
127+
setupPath: '/auth/setup', // Setup page path
128+
},
129+
},
130+
131+
// Error translation configuration
132+
errorTranslation: {
133+
enabled: true, // Translate backend error codes
134+
defaultLocale: 'de', // Fallback locale
71135
},
72136

73137
// TUS upload configuration
@@ -298,9 +362,12 @@ The package works **with or without** `@nuxtjs/i18n`:
298362
| Composable | Description |
299363
|------------|-------------|
300364
| `useLtAuth()` | Better-Auth integration with session, passkey, 2FA |
365+
| `useLtAuthClient()` | Direct access to the Better-Auth client singleton |
366+
| `useLtErrorTranslation()` | Translate backend error codes to user-friendly messages |
301367
| `useLtTusUpload()` | TUS protocol file uploads with pause/resume |
302368
| `useLtFile()` | File utilities (size formatting, URLs) |
303369
| `useLtShare()` | Web Share API with clipboard fallback |
370+
| `useSystemSetup()` | System setup flow for initial admin user creation |
304371

305372
### Components
306373

package.json

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lenne.tech/nuxt-extensions",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "Reusable Nuxt 4 composables, components, and Better-Auth integration for lenne.tech projects",
55
"repository": {
66
"type": "git",
@@ -12,7 +12,7 @@
1212
},
1313
"author": "lenne.Tech <info@lenne.tech> (https://lenne.tech)",
1414
"license": "MIT",
15-
"packageManager": "pnpm@10.29.2",
15+
"packageManager": "pnpm@10.32.1",
1616
"type": "module",
1717
"exports": {
1818
".": {
@@ -69,7 +69,7 @@
6969
"release": "pnpm format:check && pnpm lint && pnpm test:types && pnpm test && pnpm prepack"
7070
},
7171
"dependencies": {
72-
"@nuxt/kit": "4.3.0"
72+
"@nuxt/kit": "4.4.2"
7373
},
7474
"peerDependencies": {
7575
"@better-auth/passkey": ">=1.0.0",
@@ -93,30 +93,37 @@
9393
}
9494
},
9595
"devDependencies": {
96-
"@better-auth/passkey": "1.4.18",
97-
"@nuxt/devtools": "3.1.1",
98-
"@playwright/test": "1.58.1",
96+
"@better-auth/passkey": "1.5.5",
97+
"@nuxt/devtools": "3.2.3",
9998
"@nuxt/module-builder": "1.0.2",
100-
"@nuxt/schema": "4.3.0",
101-
"@nuxt/test-utils": "3.23.0",
102-
"@types/node": "25.2.0",
103-
"@vitest/coverage-v8": "4.0.18",
104-
"@vue/test-utils": "2.4.6",
105-
"better-auth": "1.4.18",
106-
"happy-dom": "20.5.0",
107-
"nuxt": "4.3.0",
108-
"oxfmt": "0.28.0",
109-
"oxlint": "1.43.0",
99+
"@nuxt/schema": "4.4.2",
100+
"@playwright/test": "1.58.2",
101+
"@types/node": "25.5.0",
102+
"@vitest/coverage-v8": "4.1.0",
103+
"better-auth": "1.5.5",
104+
"happy-dom": "20.8.4",
105+
"nuxt": "4.4.2",
106+
"oxfmt": "0.40.0",
107+
"oxlint": "1.55.0",
110108
"tus-js-client": "4.3.1",
111109
"typescript": "5.9.3",
112-
"vitest": "4.0.18",
113-
"vue-tsc": "3.2.4"
110+
"vitest": "4.1.0",
111+
"vue-tsc": "3.2.5"
114112
},
115113
"pnpm": {
116114
"onlyBuiltDependencies": [
117115
"@parcel/watcher",
118116
"esbuild"
119-
]
117+
],
118+
"overrides": {
119+
"minimatch@>=5.0.0 <5.1.8": "5.1.8",
120+
"minimatch@>=9.0.0 <9.0.7": "9.0.7",
121+
"minimatch@>=10.0.0 <10.2.3": "10.2.3",
122+
"rollup@>=4.0.0 <4.59.0": ">=4.59.0",
123+
"serialize-javascript@<=7.0.2": ">=7.0.3",
124+
"svgo@=4.0.0": ">=4.0.1",
125+
"tar@<7.5.11": "7.5.11"
126+
}
120127
},
121128
"keywords": [
122129
"nuxt",

0 commit comments

Comments
 (0)