nuxt-authenticate-module 1.0.0 → 1.2.2
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 +1 -40
- package/dist/module.json +1 -1
- package/dist/module.mjs +22 -2
- package/package.json +15 -14
package/README.md
CHANGED
|
@@ -32,17 +32,9 @@ El diseño busca estandarizar la autenticación entre microservicios manteniendo
|
|
|
32
32
|
Instala el módulo en tu aplicación Nuxt con el siguiente comando:
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
|
-
npm install authenticate-module
|
|
35
|
+
npm install nuxt-authenticate-module
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Si está en un repositorio interno:
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
git submodule add <repository-url> modules/authenticate-module
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
38
|
## Configuración
|
|
47
39
|
|
|
48
40
|
### 1. Configuración de Nuxt
|
|
@@ -65,31 +57,12 @@ Configura las siguientes variables en tu archivo `.env`. Nota: `DATABASE_URL` es
|
|
|
65
57
|
```env
|
|
66
58
|
# Base de datos (SQL Server) — Opcional si provees repositorios
|
|
67
59
|
DATABASE_URL="sqlserver://servidor:puerto;database=nombre_db;user=usuario;password=contraseña;encrypt=true"
|
|
68
|
-
|
|
69
|
-
# Clave secreta para JWT — Requerida
|
|
70
|
-
JWT_SECRET="tu_clave_secreta_super_segura"
|
|
71
60
|
```
|
|
72
61
|
|
|
73
62
|
### Inversión de Dependencias
|
|
74
63
|
|
|
75
64
|
El módulo está diseñado para recibir implementaciones de repositorios y proveedores desde la aplicación que lo usa. Proporciona utilidades en `runtime/utility` (`getUserRepository`, `getSessionRepository`) como contratos por defecto. Puedes inyectar tus implementaciones en la configuración del módulo o a través de composables/servicios en runtime.
|
|
76
65
|
|
|
77
|
-
Ejemplo (inyección en `nuxt.config.ts`):
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
export default defineNuxtConfig({
|
|
81
|
-
modules: ['./modules/authenticate-module/src/module'],
|
|
82
|
-
authenticateModule: {
|
|
83
|
-
providers: {
|
|
84
|
-
userRepository: () => createMyUserRepository(),
|
|
85
|
-
sessionRepository: () => createMySessionRepository(),
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Si no se proporcionan proveedores, el módulo puede usar la implementación incluida (Prisma) si está disponible.
|
|
92
|
-
|
|
93
66
|
### Inyección vía Middleware
|
|
94
67
|
|
|
95
68
|
La inyección de dependencias en este módulo se realiza típicamente desde un middleware que adjunta las implementaciones de repositorios al contexto de los eventos. En el playground existe un ejemplo en `playground/server/middleware/auth/inject-repository.ts` que muestra cómo resolver proveedores y exponerlos en `event.context`.
|
|
@@ -116,17 +89,6 @@ export default defineEventHandler(async (event) => {
|
|
|
116
89
|
|
|
117
90
|
Los controladores y servicios del módulo pueden entonces obtener los repositorios desde `event.context` o usando los helpers del runtime (`getUserRepository`, `getSessionRepository`) que consultan ese contexto.
|
|
118
91
|
|
|
119
|
-
### 3. Configuración de Prisma
|
|
120
|
-
|
|
121
|
-
Si decides usar la implementación incluida basada en Prisma, ejecuta las migraciones de la base de datos:
|
|
122
|
-
|
|
123
|
-
```bash
|
|
124
|
-
npx prisma migrate deploy
|
|
125
|
-
npx prisma generate
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Si en su lugar inyectas repositorios personalizados (p. ej. el microservicio comparte su propio cliente), no es necesario ejecutar estas migraciones para que el módulo funcione.
|
|
129
|
-
|
|
130
92
|
---
|
|
131
93
|
|
|
132
94
|
## Uso
|
|
@@ -290,7 +252,6 @@ model Session {
|
|
|
290
252
|
## Seguridad
|
|
291
253
|
|
|
292
254
|
- **Encriptación de contraseñas**: Uso de bcrypt con salt rounds configurables
|
|
293
|
-
- **Tokens JWT**: Firmados con clave secreta robusta
|
|
294
255
|
- **Validación de entrada**: Sanitización de datos de usuario
|
|
295
256
|
- **Auditoría**: Registro de cambios en UserHistory
|
|
296
257
|
- **Expiración de sesiones**: Control de tiempo de vida de tokens
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -37,13 +37,33 @@ const module$1 = defineNuxtModule({
|
|
|
37
37
|
utility: resolve("./runtime/server/utility"),
|
|
38
38
|
service: resolve("./runtime/server/service")
|
|
39
39
|
});
|
|
40
|
+
nuxt.options.typescript.tsConfig = nuxt.options.typescript.tsConfig || {};
|
|
41
|
+
nuxt.options.typescript.tsConfig = {
|
|
42
|
+
...nuxt.options.typescript.tsConfig,
|
|
43
|
+
compilerOptions: {
|
|
44
|
+
baseUrl: ".",
|
|
45
|
+
paths: {
|
|
46
|
+
"modules/*": ["./src/runtime/server/modules/*"],
|
|
47
|
+
"testkit/*": ["./test/test-kit/*"],
|
|
48
|
+
"testkit": ["./test/test-kit"],
|
|
49
|
+
"prisma": ["./playground/server/utils/prisma.db.ts"],
|
|
50
|
+
"service/*": ["./src/runtime/server/service/*"],
|
|
51
|
+
"service": ["./src/runtime/server/service"]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
exclude: [
|
|
55
|
+
"dist",
|
|
56
|
+
"node_modules",
|
|
57
|
+
"playground"
|
|
58
|
+
]
|
|
59
|
+
};
|
|
40
60
|
addComponentsDir({
|
|
41
61
|
path: resolve("./runtime/components"),
|
|
42
62
|
prefix: options.prefix || "Auth"
|
|
43
63
|
});
|
|
44
64
|
addImportsDir(resolve("./runtime/composable"));
|
|
45
65
|
addServerHandler({
|
|
46
|
-
handler: resolve("./runtime/server/middleware/session
|
|
66
|
+
handler: resolve("./runtime/server/middleware/session"),
|
|
47
67
|
middleware: true
|
|
48
68
|
});
|
|
49
69
|
apiRoutes.forEach(({ route, handler }) => {
|
|
@@ -54,7 +74,7 @@ const module$1 = defineNuxtModule({
|
|
|
54
74
|
});
|
|
55
75
|
addRouteMiddleware({
|
|
56
76
|
name: "protected",
|
|
57
|
-
path: resolve("./runtime/middleware/protected
|
|
77
|
+
path: resolve("./runtime/middleware/protected"),
|
|
58
78
|
global: false
|
|
59
79
|
});
|
|
60
80
|
nuxt.hook("pages:extend", (pages) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-authenticate-module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Módulo de autenticación con inversión de dependencias",
|
|
5
5
|
"repository": "jmg03ndorg/authenticate-module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,13 +22,25 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prepack": "nuxt-module-build build",
|
|
27
|
+
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
28
|
+
"dev:build": "nuxi build playground",
|
|
29
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
30
|
+
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
31
|
+
"lint": "eslint .",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:watch": "vitest watch",
|
|
34
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
35
|
+
},
|
|
25
36
|
"dependencies": {
|
|
26
37
|
"@nuxt/kit": "4.2.2",
|
|
27
38
|
"@nuxt/ui": "https://pkg.pr.new/@nuxt/ui@5106",
|
|
28
39
|
"@prisma/adapter-mssql": "^7.2.0",
|
|
29
40
|
"@prisma/client": "^7.2.0",
|
|
30
41
|
"bcrypt": "6.0.0",
|
|
31
|
-
"mssql": "^12.2.0"
|
|
42
|
+
"mssql": "^12.2.0",
|
|
43
|
+
"nuxt-auth-utils": "^0.5.27"
|
|
32
44
|
},
|
|
33
45
|
"devDependencies": {
|
|
34
46
|
"@iconify-json/lucide": "^1.2.82",
|
|
@@ -50,20 +62,9 @@
|
|
|
50
62
|
"happy-dom": "^20.0.11",
|
|
51
63
|
"magicast": "^0.3.5",
|
|
52
64
|
"nuxt": "4.2.2",
|
|
53
|
-
"nuxt-auth-utils": "^0.5.26",
|
|
54
65
|
"prisma": "^7.2.0",
|
|
55
66
|
"typescript": "5.9.2",
|
|
56
67
|
"vitest": "3.2.4",
|
|
57
68
|
"vue-tsc": "3.0.6"
|
|
58
|
-
},
|
|
59
|
-
"scripts": {
|
|
60
|
-
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
61
|
-
"dev:build": "nuxi build playground",
|
|
62
|
-
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
63
|
-
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
64
|
-
"lint": "eslint .",
|
|
65
|
-
"test": "vitest run",
|
|
66
|
-
"test:watch": "vitest watch",
|
|
67
|
-
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
68
69
|
}
|
|
69
|
-
}
|
|
70
|
+
}
|