@innertia-solutions/innertia-nuxt 0.1.79 → 0.1.81
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 +1 -0
- package/components/Auth/LoginForm.vue +1 -1
- package/components/Auth/PasskeyButton.vue +103 -0
- package/components/Auth/PasskeyInvite.vue +76 -0
- package/components/Auth/PasskeyManager.vue +168 -0
- package/components/Auth/UserPasskeys.vue +72 -0
- package/components/Forms/Select.vue +30 -2
- package/composables/useAuth.js +9 -1
- package/composables/usePasskeys/index.ts +298 -0
- package/composables/usePasskeys/internal/__tests__/passkeys.test.ts +83 -0
- package/composables/usePasskeys/internal/__tests__/runGuard.test.ts +42 -0
- package/composables/usePasskeys/internal/passkeys.ts +80 -0
- package/composables/usePasskeys/internal/runGuard.ts +41 -0
- package/docs/passkeys.md +97 -0
- package/nuxt.config.ts +1 -1
- package/package.json +4 -3
- package/server/routes/_auth/passkey/login.post.ts +27 -0
- package/server/routes/_auth/platform/passkey/login.post.ts +25 -0
- package/server/utils/__tests__/passkeyLogin.test.ts +38 -0
- package/server/utils/passkeyLogin.ts +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innertia-solutions/innertia-nuxt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.81",
|
|
4
4
|
"description": "Innertia Solutions — Nuxt layer unificada: core, auth, multitenancy, theme y app contexts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"@floating-ui/dom": "^1.7.6",
|
|
35
35
|
"@nuxtjs/seo": "^3.4.0",
|
|
36
36
|
"@pinia/nuxt": "^0.11.3",
|
|
37
|
+
"@simplewebauthn/browser": "^13.3.0",
|
|
37
38
|
"@tabler/icons-vue": "^3.44.0",
|
|
38
39
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
39
40
|
"@tailwindcss/forms": "^0.5.10",
|
|
@@ -48,14 +49,14 @@
|
|
|
48
49
|
"date-fns": "^4.1.0",
|
|
49
50
|
"date-fns-tz": "^3.2.0",
|
|
50
51
|
"dayjs": "^1.11.0",
|
|
52
|
+
"iron-webcrypto": "^1.2.1",
|
|
51
53
|
"pinia-plugin-persistedstate": "^4.7.1",
|
|
52
54
|
"preline": "^3.2.3",
|
|
53
55
|
"pusher-js": "^8.5.0",
|
|
54
56
|
"tailwindcss": "^4.0.0",
|
|
55
57
|
"uuid": "^13.0.0",
|
|
56
58
|
"vanilla-calendar-pro": "^3.1.0",
|
|
57
|
-
"vue3-apexcharts": "^1.11.1"
|
|
58
|
-
"iron-webcrypto": "^1.2.1"
|
|
59
|
+
"vue3-apexcharts": "^1.11.1"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
62
|
"test": "vitest run"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineEventHandler, readBody, createError, getRequestHeader } from 'h3'
|
|
2
|
+
import { writeSession } from '../../../utils/session'
|
|
3
|
+
import { forwardClientHeaders } from '../../../utils/bff'
|
|
4
|
+
import { normalizePasskeyLoginResponse, passkeyLoginErrorMessage } from '../../../utils/passkeyLogin'
|
|
5
|
+
|
|
6
|
+
// Ingreso con passkey (tenant). Laravel valida la assertion y entra al primer
|
|
7
|
+
// contexto de `contexts` al que el usuario tenga acceso. En éxito sella el JWT
|
|
8
|
+
// en la sesión httpOnly con ese contexto y devuelve el body SIN token. Pasos
|
|
9
|
+
// previos (cambio forzado / verificación de correo) no traen token: no se sella.
|
|
10
|
+
export default defineEventHandler(async (event) => {
|
|
11
|
+
const { key, response, contexts } = await readBody(event)
|
|
12
|
+
const config = useRuntimeConfig(event)
|
|
13
|
+
let data: any
|
|
14
|
+
try {
|
|
15
|
+
data = await $fetch(`${config.apiInternalUrl}/auth/passkey/login`, {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
body: { key, response, contexts },
|
|
18
|
+
headers: { Accept: 'application/json', ...forwardClientHeaders(n => getRequestHeader(event, n)) },
|
|
19
|
+
})
|
|
20
|
+
} catch (err: any) {
|
|
21
|
+
const status = err?.response?.status ?? err?.statusCode ?? 500
|
|
22
|
+
throw createError({ statusCode: status, data: err?.data ?? null, statusMessage: 'passkey_login_failed', message: passkeyLoginErrorMessage(status, err?.data) })
|
|
23
|
+
}
|
|
24
|
+
const { token, body } = normalizePasskeyLoginResponse(data)
|
|
25
|
+
if (token) await writeSession(event, { token, currentContext: body.context as string | undefined })
|
|
26
|
+
return body
|
|
27
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineEventHandler, readBody, createError, getRequestHeader } from 'h3'
|
|
2
|
+
import { writeSession } from '../../../../utils/session'
|
|
3
|
+
import { forwardClientHeaders } from '../../../../utils/bff'
|
|
4
|
+
import { normalizePasskeyLoginResponse, passkeyLoginErrorMessage } from '../../../../utils/passkeyLogin'
|
|
5
|
+
|
|
6
|
+
// Ingreso con passkey a /platform (identidad separada, sin contexto de tenant).
|
|
7
|
+
// Igual que /_auth/platform/login: sella el JWT y devuelve el body sin token.
|
|
8
|
+
export default defineEventHandler(async (event) => {
|
|
9
|
+
const { key, response } = await readBody(event)
|
|
10
|
+
const config = useRuntimeConfig(event)
|
|
11
|
+
let data: any
|
|
12
|
+
try {
|
|
13
|
+
data = await $fetch(`${config.apiInternalUrl}/platform/auth/passkey/login`, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
body: { key, response },
|
|
16
|
+
headers: { Accept: 'application/json', ...forwardClientHeaders(n => getRequestHeader(event, n)) },
|
|
17
|
+
})
|
|
18
|
+
} catch (err: any) {
|
|
19
|
+
const status = err?.response?.status ?? err?.statusCode ?? 500
|
|
20
|
+
throw createError({ statusCode: status, data: err?.data ?? null, statusMessage: 'passkey_login_failed', message: passkeyLoginErrorMessage(status, err?.data) })
|
|
21
|
+
}
|
|
22
|
+
const { token, body } = normalizePasskeyLoginResponse(data)
|
|
23
|
+
if (token) await writeSession(event, { token })
|
|
24
|
+
return body
|
|
25
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { normalizePasskeyLoginResponse, passkeyLoginErrorMessage } from '../passkeyLogin'
|
|
3
|
+
|
|
4
|
+
describe('normalizePasskeyLoginResponse', () => {
|
|
5
|
+
it('separa el token y conserva el contexto elegido', () => {
|
|
6
|
+
const { token, body } = normalizePasskeyLoginResponse({ token: 't1', user: { id: 1 }, context: 'portal' })
|
|
7
|
+
expect(token).toBe('t1')
|
|
8
|
+
expect(body).toMatchObject({ user: { id: 1 }, context: 'portal' })
|
|
9
|
+
expect(body).not.toHaveProperty('token')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('un paso previo no trae token y conserva el flag, user_id y contexto', () => {
|
|
13
|
+
const { token, body } = normalizePasskeyLoginResponse({ requires_password_change: true, user_id: 7, context: 'backoffice' })
|
|
14
|
+
expect(token).toBeUndefined()
|
|
15
|
+
expect(body).toMatchObject({ requires_password_change: true, user_id: 7, context: 'backoffice' })
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('sin contexto (plataforma) no agrega la clave', () => {
|
|
19
|
+
const { body } = normalizePasskeyLoginResponse({ token: 't', user: { id: 1 } })
|
|
20
|
+
expect(body).not.toHaveProperty('context')
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('passkeyLoginErrorMessage', () => {
|
|
25
|
+
it('422 → mensaje genérico de passkey', () => {
|
|
26
|
+
expect(passkeyLoginErrorMessage(422, {})).toBe('No pudimos verificar la passkey.')
|
|
27
|
+
})
|
|
28
|
+
it('429 → demasiados intentos', () => {
|
|
29
|
+
expect(passkeyLoginErrorMessage(429, {})).toMatch(/Demasiados intentos/)
|
|
30
|
+
})
|
|
31
|
+
it('403/409 → mensaje del backend', () => {
|
|
32
|
+
expect(passkeyLoginErrorMessage(403, { message: 'Esta cuenta no tiene acceso a esta aplicación.' })).toBe('Esta cuenta no tiene acceso a esta aplicación.')
|
|
33
|
+
expect(passkeyLoginErrorMessage(409, { message: 'Usa el acceso de plataforma.' })).toBe('Usa el acceso de plataforma.')
|
|
34
|
+
})
|
|
35
|
+
it('otro error sin mensaje → genérico', () => {
|
|
36
|
+
expect(passkeyLoginErrorMessage(500, null)).toBe('No se pudo iniciar sesión con la passkey. Inténtalo de nuevo.')
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { normalizeLoginResponse, type LaravelLoginResponse } from './login'
|
|
2
|
+
|
|
3
|
+
/** Igual que normalizeLoginResponse, conservando el contexto que eligió Laravel
|
|
4
|
+
* (el ingreso con passkey recibe una lista de contextos y entra al primero válido). */
|
|
5
|
+
export function normalizePasskeyLoginResponse(data: LaravelLoginResponse & { context?: string }) {
|
|
6
|
+
const { token, body } = normalizeLoginResponse(data)
|
|
7
|
+
if (typeof data.context === 'string' && data.context) body.context = data.context
|
|
8
|
+
return { token, body }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function passkeyLoginErrorMessage(status: number, data: any): string {
|
|
12
|
+
if (status === 422) return 'No pudimos verificar la passkey.'
|
|
13
|
+
if (status === 429) return 'Demasiados intentos. Espera un minuto e inténtalo de nuevo.'
|
|
14
|
+
return (typeof data?.message === 'string' && data.message) || 'No se pudo iniciar sesión con la passkey. Inténtalo de nuevo.'
|
|
15
|
+
}
|