@devcoffee/nuxt-core 1.0.2 → 1.1.1
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/CHANGELOG.md +82 -0
- package/GUIDELINE.md +351 -0
- package/README.md +405 -84
- package/dist/module.d.mts +295 -156
- package/dist/module.d.ts +300 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +191 -36
- package/dist/runtime/app/composables/useAuthContext.d.ts +26 -0
- package/dist/runtime/app/composables/useAuthContext.js +111 -0
- package/dist/runtime/app/composables/useLogger.d.ts +3 -3
- package/dist/runtime/app/composables/useSessionContext.d.ts +22 -0
- package/dist/runtime/app/composables/useSessionContext.js +5 -0
- package/dist/runtime/app/middleware/authts.d.ts +12 -0
- package/dist/runtime/app/middleware/authts.js +101 -0
- package/dist/runtime/app/pages/authorize.d.vue.ts +3 -0
- package/dist/runtime/app/pages/authorize.vue +32 -0
- package/dist/runtime/app/pages/authorize.vue.d.ts +3 -0
- package/dist/runtime/app/plugins/authts.d.ts +82 -0
- package/dist/runtime/app/plugins/authts.js +91 -0
- package/dist/runtime/app/plugins/formatters.d.ts +29 -0
- package/dist/runtime/app/plugins/formatters.js +101 -0
- package/dist/runtime/app/plugins/locale.d.ts +37 -0
- package/dist/runtime/app/plugins/locale.js +39 -0
- package/dist/runtime/app/plugins/logging.d.ts +24 -16
- package/dist/runtime/app/plugins/logging.js +0 -1
- package/dist/runtime/app/utils/hashing.d.ts +1 -0
- package/dist/runtime/app/utils/hashing.js +3 -0
- package/dist/runtime/server/adapters/http.d.ts +5 -0
- package/dist/runtime/server/adapters/http.js +15 -0
- package/dist/runtime/server/adapters/oidc.d.ts +58 -0
- package/dist/runtime/server/adapters/oidc.js +21 -0
- package/dist/runtime/server/adapters/storage.d.ts +39 -0
- package/dist/runtime/server/adapters/storage.js +14 -0
- package/dist/runtime/server/adapters/utils.d.ts +31 -0
- package/dist/runtime/server/adapters/utils.js +28 -0
- package/dist/runtime/server/composables/useServerLogger.d.ts +3 -2
- package/dist/runtime/server/composables/useServerLogger.js +4 -4
- package/dist/runtime/server/core/crypto.d.ts +70 -0
- package/dist/runtime/server/core/crypto.js +55 -0
- package/dist/runtime/server/core/helpers.d.ts +194 -0
- package/dist/runtime/server/core/helpers.js +350 -0
- package/dist/runtime/server/core/index.d.ts +1 -0
- package/dist/runtime/server/core/index.js +1 -0
- package/dist/runtime/server/core/mutex.d.ts +19 -0
- package/dist/runtime/server/core/mutex.js +39 -0
- package/dist/runtime/server/core/nuxtAuthtsHandler.d.ts +26 -0
- package/dist/runtime/server/core/nuxtAuthtsHandler.js +238 -0
- package/dist/runtime/server/core/nuxtForwardHandler.d.ts +18 -0
- package/dist/runtime/server/core/nuxtForwardHandler.js +60 -0
- package/dist/runtime/server/dev/route/session.d.ts +2 -0
- package/dist/runtime/server/dev/route/session.js +8 -0
- package/dist/runtime/server/plugins/authts.d.ts +11 -0
- package/dist/runtime/server/plugins/authts.js +55 -0
- package/dist/runtime/server/plugins/logging.js +7 -2
- package/dist/runtime/server/tsconfig.json +3 -3
- package/dist/runtime/types/global.env.d.ts +21 -7
- package/dist/runtime/types/nitro.d.ts +7 -2
- package/dist/runtime/types/nuxt.d.ts +28 -8
- package/dist/runtime/utils.d.ts +31 -0
- package/dist/runtime/utils.js +28 -0
- package/dist/types.d.mts +6 -4
- package/package.json +45 -17
- package/dist/runtime/plugin.d.ts +0 -2
- package/dist/runtime/plugin.js +0 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## v1.1.1
|
|
4
|
+
|
|
5
|
+
[compare changes](https://github.com/coolkg1412/devcoffee-nuxt-core/compare/v1.0...v1.1.1)
|
|
6
|
+
|
|
7
|
+
### 💅 Refactors
|
|
8
|
+
|
|
9
|
+
- Sort storage adapter imports in helpers.ts; remove unused moduleText in forward handler test ([20f3496](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/20f3496))
|
|
10
|
+
|
|
11
|
+
### 🏡 Chore
|
|
12
|
+
|
|
13
|
+
- Complete v1.0 milestone — archive roadmap, requirements, retrospective ([2cb5067](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/2cb5067))
|
|
14
|
+
- Delete REQUIREMENTS.md — archived to milestones/v1.0-REQUIREMENTS.md ([48ce751](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/48ce751))
|
|
15
|
+
- Archive phase directories from v1.0 milestone ([1f3ced8](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/1f3ced8))
|
|
16
|
+
|
|
17
|
+
### ❤️ Contributors
|
|
18
|
+
|
|
19
|
+
- Hieu Nguyen <hieu.nguyen@devcoffee.tech>
|
|
20
|
+
|
|
21
|
+
## v1.1.0
|
|
22
|
+
|
|
23
|
+
[compare changes](https://github.com/coolkg1412/devcoffee-nuxt-core/compare/v1.0.2...v1.1.0)
|
|
24
|
+
|
|
25
|
+
### 🚀 Enhancements
|
|
26
|
+
|
|
27
|
+
- Add support for ignored authentication path regex patterns ([#5](https://github.com/coolkg1412/devcoffee-nuxt-core/pull/5))
|
|
28
|
+
- **04:** Adapter foundation — http/utils/storage/oidc barrel adapters (ADPT-01–04) ([3c44a78](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/3c44a78))
|
|
29
|
+
- **09:** Add E2E test coverage using Playwright ([#14](https://github.com/coolkg1412/devcoffee-nuxt-core/pull/14))
|
|
30
|
+
- **docs:** Phase 10 — README.md and GUIDELINE.md for consumers and contributors ([#15](https://github.com/coolkg1412/devcoffee-nuxt-core/pull/15))
|
|
31
|
+
- **11:** Distributed token refresh mutex — atomic Redis NX lock for multi-instance deployments ([f7e2d72](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/f7e2d72))
|
|
32
|
+
|
|
33
|
+
### 🩹 Fixes
|
|
34
|
+
|
|
35
|
+
- TypeScript ([#4](https://github.com/coolkg1412/devcoffee-nuxt-core/pull/4))
|
|
36
|
+
- Update index page test to check for non-null response ([aba39bf](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/aba39bf))
|
|
37
|
+
- **lint:** Auto-fix prettier formatting and replace dynamic delete in omit() ([89d987a](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/89d987a))
|
|
38
|
+
- **test:** Update SEC-03 source-text assertion to match prettier-formatted multiline call ([55f92d7](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/55f92d7))
|
|
39
|
+
- **types:** Resolve TypeScript strict-mode errors across app layer and server core ([b089812](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/b089812))
|
|
40
|
+
- **types:** Cast cookieOpts input before omit to resolve TS key narrowing error ([93dbb50](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/93dbb50))
|
|
41
|
+
- **types:** Include global.d.ts in Nitro server tsconfig to resolve DeepPartial on server layer ([24700e2](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/24700e2))
|
|
42
|
+
|
|
43
|
+
### 💅 Refactors
|
|
44
|
+
|
|
45
|
+
- Flatten utils paths (utils/utils.ts → utils.ts) ([45d8997](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/45d8997))
|
|
46
|
+
- **test:** Migrate test imports to @/ alias and fix tsconfig/vitest paths ([1f73e73](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/1f73e73))
|
|
47
|
+
- **utils:** Consolidate utility exports and fix module import paths ([d9e2fdc](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/d9e2fdc))
|
|
48
|
+
- **module:** Remove redundant typescript tsConfig includes covered by prepare:types hook ([9ced2c5](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/9ced2c5))
|
|
49
|
+
|
|
50
|
+
### 📖 Documentation
|
|
51
|
+
|
|
52
|
+
- **10:** Research phase for README.md and GUIDELINE.md documentation ([31d5ab0](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/31d5ab0))
|
|
53
|
+
- Resolve debug eslint-ts-type-errors ([0653761](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/0653761))
|
|
54
|
+
- Update debug knowledge base with eslint-ts-type-errors ([2dc0cc1](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/2dc0cc1))
|
|
55
|
+
|
|
56
|
+
### 🏡 Chore
|
|
57
|
+
|
|
58
|
+
- Authorize for devecoffee ([#2](https://github.com/coolkg1412/devcoffee-nuxt-core/pull/2))
|
|
59
|
+
- The base UI and common Components ([#3](https://github.com/coolkg1412/devcoffee-nuxt-core/pull/3))
|
|
60
|
+
- Update docs ([b708e93](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/b708e93))
|
|
61
|
+
- Suppress DEP0155 deprecation warning in test scripts ([6fdb696](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/6fdb696))
|
|
62
|
+
- **test:** Split test scripts and enable headed E2E mode ([207c3d5](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/207c3d5))
|
|
63
|
+
- Bump `compatibilityDate` ([2654eb2](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/2654eb2))
|
|
64
|
+
|
|
65
|
+
### ✅ Tests
|
|
66
|
+
|
|
67
|
+
- **api:** Mark BUG-03 deprecation tests as todo until implemented ([69cd623](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/69cd623))
|
|
68
|
+
- Update import aliases and trim stale todo tests for BUG-03 ([f7c5cff](https://github.com/coolkg1412/devcoffee-nuxt-core/commit/f7c5cff))
|
|
69
|
+
|
|
70
|
+
### ❤️ Contributors
|
|
71
|
+
|
|
72
|
+
- Hieu Nguyen <hieu.nguyen@devcoffee.tech>
|
|
73
|
+
- Hiếu Nguyễn ([@coolkg1412](https://github.com/coolkg1412))
|
|
74
|
+
|
|
75
|
+
## v1.0.2
|
|
76
|
+
|
|
77
|
+
[compare changes](https://github.com/coolkg1412/devcoffee-nuxt-core/compare/v1.0.1...v1.0.2)
|
|
78
|
+
|
|
79
|
+
## v1.0.1
|
|
80
|
+
|
|
81
|
+
[compare changes](https://github.com/coolkg1412/devcoffee-nuxt-core/compare/v1.0.0...v1.0.1)
|
|
82
|
+
|
package/GUIDELINE.md
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# @devcoffee/nuxt-core — Contributor Guide
|
|
2
|
+
|
|
3
|
+
This guide is for developers working on the module itself. If you are integrating the module into your app, see [README.md](./README.md).
|
|
4
|
+
|
|
5
|
+
## Quick Reference
|
|
6
|
+
|
|
7
|
+
| Topic | Section |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Module layers and responsibilities | [Architecture](#architecture) |
|
|
10
|
+
| Annotated file tree | [Directory Reference](#directory-reference) |
|
|
11
|
+
| First-time setup | [Development Setup](#development-setup) |
|
|
12
|
+
| Test commands | [Test Infrastructure](#test-infrastructure) |
|
|
13
|
+
| Adding external dependencies | [Adapter Pattern](#adapter-pattern) |
|
|
14
|
+
| Per-request auth flow | [Request Lifecycle](#request-lifecycle) |
|
|
15
|
+
| Guarded design choices | [Key Architectural Decisions](#key-architectural-decisions) |
|
|
16
|
+
| Publishing a new version | [Release Pipeline](#release-pipeline) |
|
|
17
|
+
| Planning workflow | [GSD Workflow](#gsd-workflow) |
|
|
18
|
+
| Style and naming rules | [Coding Conventions](#coding-conventions) |
|
|
19
|
+
|
|
20
|
+
## Architecture
|
|
21
|
+
|
|
22
|
+
The module is organized into five layers. Each layer has a single responsibility and strict import rules.
|
|
23
|
+
|
|
24
|
+
### Layer 1: Module Definition (`src/module.ts`)
|
|
25
|
+
|
|
26
|
+
Entry point. Configures and registers all runtime components into Nuxt and Nitro during build:
|
|
27
|
+
|
|
28
|
+
- Registers server plugins, server composables, and server handler imports via `@nuxt/kit`
|
|
29
|
+
- Registers app plugins, app composables, and route middleware
|
|
30
|
+
- Injects runtime configuration from `nuxtCore` options
|
|
31
|
+
- Sets up Nitro storage and DevTools routes
|
|
32
|
+
|
|
33
|
+
### Layer 2: Server / Nitro (`src/runtime/server/`)
|
|
34
|
+
|
|
35
|
+
All server-side auth logic. Runs in the Nitro runtime (not the browser):
|
|
36
|
+
|
|
37
|
+
- `plugins/authts.ts` — global Nitro plugin; validates and refreshes sessions on every HTTP request
|
|
38
|
+
- `core/helpers.ts` — PKCE, state, token exchange, session CRUD, token refresh mutex
|
|
39
|
+
- `core/nuxtAuthtsHandler.ts` — `NuxtAuthtsHandler` export; handles GET_SESSION, TOKEN, LOGOUT, AUTHORIZE_URL actions
|
|
40
|
+
- `core/nuxtForwardHandler.ts` — `NuxtForwardRequestHandler` export; authenticated API proxy
|
|
41
|
+
- `adapters/` — external dependency wrappers (see [Adapter Pattern](#adapter-pattern))
|
|
42
|
+
- `composables/useServerLogger.ts` — server-side logging composable
|
|
43
|
+
|
|
44
|
+
### Layer 3: Client / App (`src/runtime/app/`)
|
|
45
|
+
|
|
46
|
+
Client-side auth state, UI interactions, and route protection. Runs in Vue/Nuxt:
|
|
47
|
+
|
|
48
|
+
- `plugins/authts.ts` — app plugin; initializes session state, provides `$sessionContext`, `$sessionReady`, fires hooks
|
|
49
|
+
- `middleware/authts.ts` — global route middleware; enforces `definePageMeta` auth requirements
|
|
50
|
+
- `composables/useAuthContext.ts` — reactive auth state and actions
|
|
51
|
+
- `composables/useSessionContext.ts` — low-level session accessor
|
|
52
|
+
- `composables/useLogger.ts` — client-side logging composable
|
|
53
|
+
- `pages/authorize.vue` — OIDC callback page (auto-registered at `openid.redirectUri`)
|
|
54
|
+
|
|
55
|
+
### Layer 4: Types (`src/types/`)
|
|
56
|
+
|
|
57
|
+
All TypeScript interfaces and augmentations:
|
|
58
|
+
|
|
59
|
+
- `types/authts.d.ts` — auth types (`SessionContext`, `AuthorizedUser`, `ModuleOptions`, etc.)
|
|
60
|
+
- `types/logging.d.ts` — logging types
|
|
61
|
+
- `types/index.d.ts` — central re-export point; consumers import from `@devcoffee/nuxt-core`
|
|
62
|
+
|
|
63
|
+
### Layer 5: Module Helpers (`src/helpers.ts`)
|
|
64
|
+
|
|
65
|
+
Option normalization and public config sanitization:
|
|
66
|
+
|
|
67
|
+
- `normalizedModuleOptions()` — merges user config with defaults
|
|
68
|
+
- `normalizePublicRuntimeConfig()` — strips private fields before injecting into runtime config
|
|
69
|
+
|
|
70
|
+
## Directory Reference
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
src/
|
|
74
|
+
├── module.ts # Layer 1: Module Definition
|
|
75
|
+
├── helpers.ts # Layer 5: Option normalization + defaults
|
|
76
|
+
├── utils.ts # Utility relay (re-exports from runtime/utils)
|
|
77
|
+
├── types/
|
|
78
|
+
│ ├── index.d.ts # Central type re-export for consumers
|
|
79
|
+
│ ├── authts.d.ts # Auth types (SessionContext, AuthorizedUser, etc.)
|
|
80
|
+
│ └── logging.d.ts # Logging types
|
|
81
|
+
└── runtime/
|
|
82
|
+
├── server/ # Layer 2: Server / Nitro
|
|
83
|
+
│ ├── adapters/ # External dependency wrappers
|
|
84
|
+
│ │ ├── http.ts # h3 cookie, request, response, error functions
|
|
85
|
+
│ │ ├── oidc.ts # openid-client wrappers with module-owned types
|
|
86
|
+
│ │ ├── storage.ts # Nitro useStorage session CRUD
|
|
87
|
+
│ │ └── utils.ts # deepMerge, omit, pick (native, no lodash)
|
|
88
|
+
│ ├── core/ # Business logic — imports ONLY from adapters/
|
|
89
|
+
│ │ ├── helpers.ts
|
|
90
|
+
│ │ ├── nuxtAuthtsHandler.ts
|
|
91
|
+
│ │ └── nuxtForwardHandler.ts
|
|
92
|
+
│ ├── composables/
|
|
93
|
+
│ │ └── useServerLogger.ts
|
|
94
|
+
│ ├── plugins/
|
|
95
|
+
│ │ └── authts.ts # Per-request session validation entry point
|
|
96
|
+
│ └── dev/ # DevTools route handler
|
|
97
|
+
└── app/ # Layer 3: Client / App
|
|
98
|
+
├── composables/
|
|
99
|
+
│ ├── useAuthContext.ts
|
|
100
|
+
│ ├── useSessionContext.ts
|
|
101
|
+
│ └── useLogger.ts
|
|
102
|
+
├── middleware/
|
|
103
|
+
│ └── authts.ts # Global route protection middleware
|
|
104
|
+
├── pages/
|
|
105
|
+
│ └── authorize.vue # OIDC callback page (auto-registered)
|
|
106
|
+
├── plugins/
|
|
107
|
+
│ ├── authts.ts # Session init, hooks, $sessionReady
|
|
108
|
+
│ ├── logging.ts
|
|
109
|
+
│ ├── formatters.ts
|
|
110
|
+
│ └── locale.ts
|
|
111
|
+
└── utils/
|
|
112
|
+
└── utils.ts # Utility relay
|
|
113
|
+
|
|
114
|
+
test/
|
|
115
|
+
├── unit/ # Vitest unit tests
|
|
116
|
+
└── e2e/ # Playwright + Vitest E2E tests
|
|
117
|
+
├── fixture/ # Nuxt test app with mock OIDC server
|
|
118
|
+
└── *.test.ts
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Development Setup
|
|
122
|
+
|
|
123
|
+
### Prerequisites
|
|
124
|
+
|
|
125
|
+
- Node.js LTS (18+)
|
|
126
|
+
- npm 10+
|
|
127
|
+
- A `.certs/devcoffee.ca.pem` file — required for TLS in development (internal CA). Place the DevCoffee CA certificate at this path.
|
|
128
|
+
|
|
129
|
+
### First-time setup
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# 1. Clone and install
|
|
133
|
+
git clone <repo-url>
|
|
134
|
+
cd devcoffee-nuxt-core
|
|
135
|
+
npm install
|
|
136
|
+
|
|
137
|
+
# 2. Generate type stubs (required before dev or test)
|
|
138
|
+
npm run dev:prepare
|
|
139
|
+
|
|
140
|
+
# 3. Start the playground dev server
|
|
141
|
+
npm run dev
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The playground runs at `http://localhost:3000`. The custom CA certificate is injected via `NODE_EXTRA_CA_CERTS` in the `dev` script.
|
|
145
|
+
|
|
146
|
+
### Clean rebuild
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
npm run cleanup # Remove .nuxt and playground build artifacts
|
|
150
|
+
npm run dev:prepare
|
|
151
|
+
npm run dev
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Test Infrastructure
|
|
155
|
+
|
|
156
|
+
| Command | What it runs | When to use |
|
|
157
|
+
|---|---|---|
|
|
158
|
+
| `npm run test` | Vitest unit suite (once) | Before committing |
|
|
159
|
+
| `npm run test:watch` | Vitest unit suite (watch mode) | During development |
|
|
160
|
+
| `npm run test:types` | `vue-tsc --noEmit` type check | Before committing |
|
|
161
|
+
| `npm run test:e2e` | Playwright + Vitest E2E tests (headless) | After changing auth flow, middleware, or session handling |
|
|
162
|
+
| `npm run test:e2e:ui` | E2E tests in headed Chromium (via `PLAYWRIGHT_HEADLESS=false`) | Debugging browser-mode E2E failures |
|
|
163
|
+
| `npm run test:all` | All unit + E2E tests combined | Before opening a PR or releasing |
|
|
164
|
+
|
|
165
|
+
### Unit tests (`test/unit/`)
|
|
166
|
+
|
|
167
|
+
Written with Vitest. Use `@nuxt/test-utils` for composable and middleware tests. Mock Nitro virtual modules where needed (e.g., `vi.mock('nitropack/runtime')`).
|
|
168
|
+
|
|
169
|
+
Tests follow source-text assertions for structural code presence and behavior assertions for logic. TDD was used for SEC-*, PERF-*, MDLW-*, and SSR-* requirements — new security or behavior requirements should follow the same pattern.
|
|
170
|
+
|
|
171
|
+
### E2E tests (`test/e2e/`)
|
|
172
|
+
|
|
173
|
+
Run in Vitest but use `@playwright/test` for browser automation and `createNuxtDevServer` from `@nuxt/test-utils` to spin up the fixture Nuxt app. A mock OIDC server is embedded as a Nitro route handler in the fixture.
|
|
174
|
+
|
|
175
|
+
Key files:
|
|
176
|
+
|
|
177
|
+
- `test/e2e/fixture/` — test Nuxt app (standalone, not the playground)
|
|
178
|
+
- `test/e2e/fixture/server/routes/` — mock OIDC discovery, token, and userinfo endpoints
|
|
179
|
+
- `test/e2e/middleware.test.ts` — E2E-01 (required redirect) and E2E-02 (unauthenticatedOnly)
|
|
180
|
+
- `test/e2e/session.test.ts` — E2E-03 (session creation) and E2E-07 (token refresh)
|
|
181
|
+
- `test/e2e/auth-flow.test.ts` — E2E-04 (valid TOKEN flow), E2E-05 (invalid state), E2E-06 (LOGOUT)
|
|
182
|
+
- `test/e2e/auth-flow-browser.test.ts` — E2E-08 (browser-mode Chromium tests)
|
|
183
|
+
|
|
184
|
+
**Important:** Browser tests (`auth-flow-browser.test.ts`) are isolated in their own file to prevent `EADDRINUSE` port conflicts when two Nuxt dev servers start in the same process.
|
|
185
|
+
|
|
186
|
+
## Adapter Pattern
|
|
187
|
+
|
|
188
|
+
### Why adapters exist
|
|
189
|
+
|
|
190
|
+
Business logic in `src/runtime/server/core/` must not import directly from `h3`, `openid-client`, or any external npm package. Instead, all external calls go through adapter barrel files in `src/runtime/server/adapters/`.
|
|
191
|
+
|
|
192
|
+
**Rationale:** Adapters create a stable internal boundary. If `h3` or `openid-client` upgrades break their API, only the adapter needs to change — not every call site in the business logic. Adapters also own the type bridge between external library types and module-owned types (e.g., `OidcUserInfo`).
|
|
193
|
+
|
|
194
|
+
This rule is enforced by grep assertions in the test suite:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# These must return zero matches:
|
|
198
|
+
grep -r "from 'h3'" src/runtime/server/core/
|
|
199
|
+
grep -r "from 'openid-client'" src/runtime/server/core/
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### How to add a new external dependency
|
|
203
|
+
|
|
204
|
+
1. Install the package as a dependency
|
|
205
|
+
2. Create (or update) the appropriate adapter file in `src/runtime/server/adapters/`
|
|
206
|
+
3. Write module-owned types for any types the adapter exposes
|
|
207
|
+
4. Export only what business logic needs — keep the adapter surface minimal
|
|
208
|
+
5. Import from the adapter in `core/` files, never directly from the package
|
|
209
|
+
|
|
210
|
+
Example: adding a hypothetical `jose` utility to the http adapter:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
// src/runtime/server/adapters/http.ts
|
|
214
|
+
import { decodeJwt as _decodeJwt } from 'jose'
|
|
215
|
+
import type { JWTPayload } from './types' // module-owned type, not jose's type
|
|
216
|
+
|
|
217
|
+
export function decodeJwt(token: string): JWTPayload {
|
|
218
|
+
return _decodeJwt(token) as JWTPayload
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Request Lifecycle
|
|
223
|
+
|
|
224
|
+
Every HTTP request to the Nuxt app passes through this sequence:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
HTTP request
|
|
228
|
+
│
|
|
229
|
+
▼
|
|
230
|
+
Nitro server plugin (src/runtime/server/plugins/authts.ts)
|
|
231
|
+
│ Reads session cookie → validateSession()
|
|
232
|
+
│ If authenticated + near-expiry → refreshTokenIfNeeded() [mutex-protected per session]
|
|
233
|
+
│ Sets event.context.sessionId
|
|
234
|
+
│
|
|
235
|
+
▼
|
|
236
|
+
Route handler (src/runtime/server/core/nuxtAuthtsHandler.ts)
|
|
237
|
+
│ Reads action from URL path: GET_SESSION | TOKEN | LOGOUT | AUTHORIZE_URL
|
|
238
|
+
│ Calls getSession(event.context.sessionId) → reads + decrypts session from storage
|
|
239
|
+
│ Dispatches to action handler
|
|
240
|
+
│
|
|
241
|
+
▼
|
|
242
|
+
Client (src/runtime/app/plugins/authts.ts)
|
|
243
|
+
│ useAsyncData('authts:session') fetches /api/_auth/session on SSR
|
|
244
|
+
│ Sets $sessionReady promise — resolved before route middleware runs
|
|
245
|
+
│
|
|
246
|
+
▼
|
|
247
|
+
Route middleware (src/runtime/app/middleware/authts.ts)
|
|
248
|
+
│ Awaits $sessionReady
|
|
249
|
+
│ Reads definePageMeta({ authts: { required, unauthenticatedOnly } })
|
|
250
|
+
│ Redirects or aborts navigation based on auth state
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Authorization code flow (login)
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
User clicks login
|
|
257
|
+
│
|
|
258
|
+
▼
|
|
259
|
+
useAuthContext.login(redirectTo)
|
|
260
|
+
│ GET /api/_auth/authorize-url → returns OIDC authorization URL
|
|
261
|
+
│ Stores redirectTo in session cookie (auths.redirect)
|
|
262
|
+
│
|
|
263
|
+
▼
|
|
264
|
+
Browser redirects to OIDC provider
|
|
265
|
+
│
|
|
266
|
+
▼
|
|
267
|
+
Provider redirects to /authorize?code=...&state=...
|
|
268
|
+
│
|
|
269
|
+
▼
|
|
270
|
+
authorize.vue (auto-registered OIDC callback page)
|
|
271
|
+
│ useAuthContext.authorize(code, state)
|
|
272
|
+
│ POST /api/_auth/token → validates state, exchanges code for tokens
|
|
273
|
+
│ If autoFetchUser: fetches userinfo from provider
|
|
274
|
+
│ Stores session in Nitro storage (tokenSet encrypted if secret is set)
|
|
275
|
+
│ Fires user:loggedIn hook
|
|
276
|
+
│
|
|
277
|
+
▼
|
|
278
|
+
Browser redirects to intended destination
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Key Architectural Decisions
|
|
282
|
+
|
|
283
|
+
These decisions are enforced by tests or type constraints. Changing them requires updating the tests that guard them.
|
|
284
|
+
|
|
285
|
+
| Decision | What it means |
|
|
286
|
+
|---|---|
|
|
287
|
+
| `sessions.secret` empty = no signing | Backward compatible — existing deployments without a secret continue working. Insecure for new deployments. |
|
|
288
|
+
| HKDF-SHA256 derives AES key from `sessions.secret` | Domain-separated with `'devcoffee-authts-tokenset-v1'` info string |
|
|
289
|
+
| Cookie names are `auths.ssid`, `auths.state`, `auths.pkce`, `auths.redirect` | Configured in `sessions.names` defaults in `src/helpers.ts` |
|
|
290
|
+
| `deleteSession()` is separate from `renewSession()` | Logout deletes the session and does not create a replacement. Prevents zombie sessions. |
|
|
291
|
+
| Token refresh mutex per session | Lock is placed inside `accessExpired && refreshToken` branch only — no storage overhead for non-expiring tokens |
|
|
292
|
+
| Adapter import enforcement | Verified by grep in test suite. Zero direct `h3` or `openid-client` imports allowed in `core/`. |
|
|
293
|
+
| `usePkce: false` in E2E fixture | PKCE threading through test requires additional cookie management. PKCE is fully covered at the unit layer. |
|
|
294
|
+
|
|
295
|
+
Full decision log: see `## Decisions` in `.planning/STATE.md`.
|
|
296
|
+
|
|
297
|
+
## Release Pipeline
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
npm run release
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
This runs in sequence: `lint` → `test:all` → `prepack` → `changelogen` → `npm publish` → `git push --follow-tags`.
|
|
304
|
+
|
|
305
|
+
Individual steps:
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
npm run lint # ESLint check (with --fix)
|
|
309
|
+
npm run test # Vitest unit suite
|
|
310
|
+
npm run test:types # vue-tsc type check
|
|
311
|
+
npm run test:all # All unit + E2E tests combined
|
|
312
|
+
npm run prepack # Build module dist (ES module + .d.ts types via @nuxt/module-builder)
|
|
313
|
+
npm run release # Full pipeline (lint + test:all + prepack + changelogen + publish + push)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
The published package is `@devcoffee/nuxt-core`. The `dist/` directory is generated by `@nuxt/module-builder` and is what consumers install.
|
|
317
|
+
|
|
318
|
+
## GSD Workflow
|
|
319
|
+
|
|
320
|
+
This project uses a phase-based planning system. All code changes must go through a GSD command to keep planning artifacts in sync.
|
|
321
|
+
|
|
322
|
+
| Task type | Entry point |
|
|
323
|
+
|---|---|
|
|
324
|
+
| Small fix or ad-hoc change | `/gsd:quick` |
|
|
325
|
+
| Bug investigation | `/gsd:debug` |
|
|
326
|
+
| Planned phase work | `/gsd:execute-phase` |
|
|
327
|
+
|
|
328
|
+
Planning artifacts live in `.planning/`:
|
|
329
|
+
|
|
330
|
+
- `ROADMAP.md` — all phases and their requirements
|
|
331
|
+
- `STATE.md` — current position, accumulated decisions, blockers
|
|
332
|
+
- `phases/NN-slug/` — per-phase RESEARCH.md, PLAN.md files, SUMMARY.md files
|
|
333
|
+
|
|
334
|
+
Do not make direct file edits outside a GSD workflow unless explicitly bypassing it.
|
|
335
|
+
|
|
336
|
+
## Coding Conventions
|
|
337
|
+
|
|
338
|
+
Key rules (full reference: `CLAUDE.md`):
|
|
339
|
+
|
|
340
|
+
- **No semicolons** — Prettier enforces this
|
|
341
|
+
- **Single quotes** for strings
|
|
342
|
+
- **2-space indent**, 120-char line length
|
|
343
|
+
- **Trailing commas:** es5 style (objects and arrays, not function parameters)
|
|
344
|
+
- **TypeScript strict** — no `any` in public API surface
|
|
345
|
+
- **Composables:** `use[Name].ts` file and function name
|
|
346
|
+
- **Server handlers:** `Nuxt[Name]Handler` (PascalCase with `Nuxt` prefix)
|
|
347
|
+
- **Getters:** `get[Name]`, **Setters:** `set[Name]`, **Validators:** `validate[Name]`
|
|
348
|
+
- **Logging:** Use `useLogger` on client, `useServerLogger` on server. Always include `tag` and `level`.
|
|
349
|
+
- **Error handling:** `createError()` from h3 for server errors, `abortNavigation(createError())` for middleware
|
|
350
|
+
- **Imports:** Prefer named imports. Use `#imports` for Nuxt auto-imports.
|
|
351
|
+
- **JSDoc:** All public functions and composables must have JSDoc with `@param`, `@returns`, `@example`, `@since 1.0.0`
|