@innertia-solutions/innertia-nuxt 0.1.81 → 0.1.82
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 -1
- package/components/Auth/PasskeyButton.vue +4 -2
- package/components/Auth/PasskeyInvite.vue +4 -2
- package/components/Auth/PasskeyManager.vue +10 -2
- package/components/Auth/PasskeySettings.vue +130 -0
- package/composables/usePasskeys/index.ts +52 -2
- package/composables/usePasskeys/internal/__tests__/statusCache.test.ts +38 -0
- package/composables/usePasskeys/internal/statusCache.ts +43 -0
- package/docs/passkeys.md +12 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,7 @@ All notable changes to `@innertia-solutions/innertia-nuxt` are documented here.
|
|
|
6
6
|
|
|
7
7
|
### Added
|
|
8
8
|
|
|
9
|
-
- Passkeys (WebAuthn): composable `usePasskeys()`, componentes `Auth.PasskeyButton` (login tenant y `/platform`, con autocompletado), `Auth.PasskeyInvite`, `Auth.PasskeyManager` y `Auth.UserPasskeys`, y rutas BFF `/_auth/passkey/login` y `/_auth/platform/passkey/login` que sellan la sesión solo si hay token.
|
|
9
|
+
- Passkeys (WebAuthn): composable `usePasskeys()`, componentes `Auth.PasskeyButton` (login tenant y `/platform`, con autocompletado), `Auth.PasskeyInvite`, `Auth.PasskeyManager` y `Auth.UserPasskeys`, y rutas BFF `/_auth/passkey/login` y `/_auth/platform/passkey/login` que sellan la sesión solo si hay token. Se activa y desactiva desde `/platform` con `Auth.PasskeySettings` (sin variables de entorno). Ver `docs/passkeys.md`.
|
|
10
10
|
- `Kanban.Standard`: reordenamiento intra-columna con drag&drop (prop `reorderEndpoint`); orden por `position`, placeholder de inserción, y persistencia vía POST. Retrocompatible: sin la prop se comporta igual que antes (solo cross-column).
|
|
11
11
|
|
|
12
12
|
### Fixed
|
|
@@ -6,6 +6,8 @@ import { IconFingerprint } from '@tabler/icons-vue'
|
|
|
6
6
|
// sin contexts el composable lanza 'PasskeyButton requiere contexts' antes de
|
|
7
7
|
// cualquier ceremonia (el backend exige al menos uno).
|
|
8
8
|
// - platform: login de /platform.
|
|
9
|
+
// - Solo se muestra si el navegador lo soporta y el interruptor de plataforma está
|
|
10
|
+
// encendido (GET auth/passkey/status); si no, no renderiza nada.
|
|
9
11
|
// - autofill: además arranca el autocompletado (el campo de correo del form
|
|
10
12
|
// debe tener autocomplete="username webauthn"; sin ese input no arranca).
|
|
11
13
|
// Emite success(data) con el body del BFF (data.context; data.tenantDestination
|
|
@@ -25,7 +27,7 @@ const props = defineProps({
|
|
|
25
27
|
})
|
|
26
28
|
const emit = defineEmits(['success', 'pending', 'error'])
|
|
27
29
|
|
|
28
|
-
const passkeys = usePasskeys()
|
|
30
|
+
const passkeys = usePasskeys({ platform: props.platform })
|
|
29
31
|
const loading = ref(false)
|
|
30
32
|
const error = ref('')
|
|
31
33
|
let mounted = false
|
|
@@ -86,7 +88,7 @@ onBeforeUnmount(() => {
|
|
|
86
88
|
</script>
|
|
87
89
|
|
|
88
90
|
<template>
|
|
89
|
-
<div v-if="passkeys.
|
|
91
|
+
<div v-if="passkeys.available.value" class="space-y-2">
|
|
90
92
|
<button
|
|
91
93
|
type="button"
|
|
92
94
|
:disabled="loading"
|
|
@@ -8,7 +8,7 @@ const props = defineProps({
|
|
|
8
8
|
base: { type: String, default: 'auth' },
|
|
9
9
|
})
|
|
10
10
|
|
|
11
|
-
const passkeys = usePasskeys()
|
|
11
|
+
const passkeys = usePasskeys({ platform: props.base === 'platform/auth' })
|
|
12
12
|
const authStore = useAuthStore()
|
|
13
13
|
const toast = useToast()
|
|
14
14
|
const visible = ref(false)
|
|
@@ -28,11 +28,13 @@ function dismiss() {
|
|
|
28
28
|
// usePasskeys resuelve `supported` en su propio onMounted, que corre antes que este.
|
|
29
29
|
onMounted(async () => {
|
|
30
30
|
if (!userId.value || !passkeys.supported.value) return
|
|
31
|
+
// Interruptor apagado: ni se consulta la lista.
|
|
32
|
+
if (!(await passkeys.ensureEnabled())) return
|
|
31
33
|
let hasPasskeys = true
|
|
32
34
|
try { hasPasskeys = (await passkeys.list(props.base)).length > 0 } catch { return }
|
|
33
35
|
visible.value = shouldShowPasskeyInvite({
|
|
34
36
|
supported: passkeys.supported.value,
|
|
35
|
-
enabled:
|
|
37
|
+
enabled: passkeys.enabled.value,
|
|
36
38
|
dismissed: dismissed(),
|
|
37
39
|
hasPasskeys,
|
|
38
40
|
loggedInWithPasskey: passkeys.loggedInWithPasskey(),
|
|
@@ -6,7 +6,7 @@ const props = defineProps({
|
|
|
6
6
|
base: { type: String, default: 'auth' },
|
|
7
7
|
})
|
|
8
8
|
|
|
9
|
-
const passkeys = usePasskeys()
|
|
9
|
+
const passkeys = usePasskeys({ platform: props.base === 'platform/auth' })
|
|
10
10
|
const toast = useToast()
|
|
11
11
|
const { confirm } = useModal()
|
|
12
12
|
const items = ref([])
|
|
@@ -22,6 +22,10 @@ const fmt = (iso) => iso ? new Date(iso).toLocaleDateString('es-CL', { day: 'num
|
|
|
22
22
|
async function load() {
|
|
23
23
|
loading.value = true
|
|
24
24
|
loadError.value = ''
|
|
25
|
+
if (!(await passkeys.ensureEnabled())) {
|
|
26
|
+
loading.value = false
|
|
27
|
+
return
|
|
28
|
+
}
|
|
25
29
|
try {
|
|
26
30
|
items.value = await passkeys.list(props.base)
|
|
27
31
|
} catch (e) {
|
|
@@ -99,7 +103,7 @@ onMounted(load)
|
|
|
99
103
|
<p class="mt-0.5 text-xs text-muted-foreground">Ingresa con tu huella, rostro o PIN del dispositivo, sin contraseña.</p>
|
|
100
104
|
</div>
|
|
101
105
|
<App.Button
|
|
102
|
-
v-if="passkeys.ready.value && passkeys.
|
|
106
|
+
v-if="passkeys.ready.value && passkeys.available.value"
|
|
103
107
|
text="Agregar en este dispositivo"
|
|
104
108
|
:icon="IconPlus"
|
|
105
109
|
severity="primary"
|
|
@@ -111,6 +115,10 @@ onMounted(load)
|
|
|
111
115
|
|
|
112
116
|
<div v-if="!passkeys.ready.value" class="px-5 py-6 text-sm text-muted-foreground">Cargando…</div>
|
|
113
117
|
|
|
118
|
+
<p v-else-if="!passkeys.enabled.value" class="px-5 py-4 text-sm text-muted-foreground">
|
|
119
|
+
El ingreso con passkey está desactivado.
|
|
120
|
+
</p>
|
|
121
|
+
|
|
114
122
|
<p v-else-if="!passkeys.supported.value" class="px-5 py-4 text-sm text-muted-foreground">
|
|
115
123
|
Este navegador no permite usar passkeys.
|
|
116
124
|
</p>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
// Consola /platform: interruptor del ingreso con passkey (guardado en BD).
|
|
3
|
+
// El producto registra las rutas con \Innertia\Passkeys\Routes::platformSettings('')
|
|
4
|
+
// en su grupo platform. GET/PUT platform/passkeys/settings.
|
|
5
|
+
const api = useApi()
|
|
6
|
+
const toast = useToast()
|
|
7
|
+
const passkeys = usePasskeys({ platform: true })
|
|
8
|
+
|
|
9
|
+
const settings = ref(null)
|
|
10
|
+
const loading = ref(true)
|
|
11
|
+
const loadError = ref('')
|
|
12
|
+
const saving = ref(false)
|
|
13
|
+
|
|
14
|
+
function errorText(e) {
|
|
15
|
+
return e?.data?.message || e?.message || 'No se pudo completar la operación.'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function load() {
|
|
19
|
+
loading.value = true
|
|
20
|
+
loadError.value = ''
|
|
21
|
+
try {
|
|
22
|
+
const res = await api.get('platform/passkeys/settings')
|
|
23
|
+
if (!res) throw new Error('Tu sesión expiró.')
|
|
24
|
+
settings.value = res
|
|
25
|
+
} catch (e) {
|
|
26
|
+
loadError.value = errorText(e)
|
|
27
|
+
} finally {
|
|
28
|
+
loading.value = false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Optimista: se refleja al instante y se revierte si el servidor falla.
|
|
33
|
+
async function toggle(key) {
|
|
34
|
+
if (!settings.value || saving.value) return
|
|
35
|
+
const previous = { ...settings.value }
|
|
36
|
+
const next = !settings.value[key]
|
|
37
|
+
settings.value = { ...settings.value, [key]: next }
|
|
38
|
+
saving.value = true
|
|
39
|
+
try {
|
|
40
|
+
const body = { enabled: key === 'enabled' ? next : previous.enabled }
|
|
41
|
+
if (key === 'allow_subdomains') body.allow_subdomains = next
|
|
42
|
+
const res = await api.put('platform/passkeys/settings', body)
|
|
43
|
+
if (!res) throw new Error('Tu sesión expiró.')
|
|
44
|
+
settings.value = res
|
|
45
|
+
await passkeys.refreshStatus()
|
|
46
|
+
toast.success('Configuración de passkeys guardada.')
|
|
47
|
+
} catch (e) {
|
|
48
|
+
settings.value = previous
|
|
49
|
+
toast.error(errorText(e))
|
|
50
|
+
} finally {
|
|
51
|
+
saving.value = false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onMounted(load)
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<template>
|
|
59
|
+
<div class="rounded-card border border-card-line bg-card">
|
|
60
|
+
<div class="border-b border-card-line px-5 py-4">
|
|
61
|
+
<h3 class="text-sm font-semibold text-foreground">Passkeys</h3>
|
|
62
|
+
<p class="mt-0.5 text-xs text-muted-foreground">Configuración del ingreso con passkey para todos los usuarios.</p>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<div v-if="loading" class="px-5 py-6 text-sm text-muted-foreground">Cargando…</div>
|
|
66
|
+
|
|
67
|
+
<div v-else-if="loadError" class="flex items-center justify-between gap-3 px-5 py-6" role="alert">
|
|
68
|
+
<p class="text-sm text-red-600">{{ loadError }}</p>
|
|
69
|
+
<App.Button text="Reintentar" size="sm" @click="load" />
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div v-else-if="settings" class="divide-y divide-card-line">
|
|
73
|
+
<div class="flex items-start justify-between gap-6 px-5 py-4">
|
|
74
|
+
<div class="space-y-1">
|
|
75
|
+
<p class="text-sm font-medium text-foreground">Ingreso con passkey</p>
|
|
76
|
+
<p class="text-sm text-muted-foreground">
|
|
77
|
+
Permite ingresar con huella, rostro o PIN del dispositivo. La contraseña sigue funcionando.
|
|
78
|
+
</p>
|
|
79
|
+
</div>
|
|
80
|
+
<button
|
|
81
|
+
type="button"
|
|
82
|
+
role="switch"
|
|
83
|
+
:aria-checked="!!settings.enabled"
|
|
84
|
+
:disabled="saving"
|
|
85
|
+
class="relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors focus:outline-hidden focus:ring-2 focus:ring-primary/30 disabled:opacity-50"
|
|
86
|
+
:class="settings.enabled ? 'bg-primary' : 'bg-slate-300 dark:bg-slate-600'"
|
|
87
|
+
@click="toggle('enabled')"
|
|
88
|
+
>
|
|
89
|
+
<span class="sr-only">Ingreso con passkey</span>
|
|
90
|
+
<span
|
|
91
|
+
class="inline-block size-5 rounded-full bg-white shadow transition-transform"
|
|
92
|
+
:class="settings.enabled ? 'translate-x-5' : 'translate-x-0.5'"
|
|
93
|
+
/>
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div class="flex items-start justify-between gap-6 px-5 py-4">
|
|
98
|
+
<div class="space-y-1">
|
|
99
|
+
<p class="text-sm font-medium text-foreground">Permitir subdominios</p>
|
|
100
|
+
<p class="text-sm text-muted-foreground">
|
|
101
|
+
Las passkeys valen también en los subdominios de los tenants (por ejemplo, acme.{{ settings.rp_id }}).
|
|
102
|
+
Actívalo solo si los tenants viven en subdominios.
|
|
103
|
+
</p>
|
|
104
|
+
</div>
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
role="switch"
|
|
108
|
+
:aria-checked="!!settings.allow_subdomains"
|
|
109
|
+
:disabled="saving"
|
|
110
|
+
class="relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors focus:outline-hidden focus:ring-2 focus:ring-primary/30 disabled:opacity-50"
|
|
111
|
+
:class="settings.allow_subdomains ? 'bg-primary' : 'bg-slate-300 dark:bg-slate-600'"
|
|
112
|
+
@click="toggle('allow_subdomains')"
|
|
113
|
+
>
|
|
114
|
+
<span class="sr-only">Permitir subdominios</span>
|
|
115
|
+
<span
|
|
116
|
+
class="inline-block size-5 rounded-full bg-white shadow transition-transform"
|
|
117
|
+
:class="settings.allow_subdomains ? 'translate-x-5' : 'translate-x-0.5'"
|
|
118
|
+
/>
|
|
119
|
+
</button>
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<div class="space-y-1 px-5 py-4 text-xs text-muted-foreground">
|
|
123
|
+
<p>Dominio: <span class="font-medium text-foreground">{{ settings.rp_id }}</span></p>
|
|
124
|
+
<p v-if="settings.origins?.length">
|
|
125
|
+
Orígenes: <span class="text-foreground">{{ settings.origins.join(', ') }}</span>
|
|
126
|
+
</p>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
</template>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, getCurrentInstance, onMounted, onBeforeUnmount } from 'vue'
|
|
1
|
+
import { ref, computed, getCurrentInstance, onMounted, onBeforeUnmount } from 'vue'
|
|
2
2
|
import {
|
|
3
3
|
startAuthentication,
|
|
4
4
|
startRegistration,
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
WEBAUTHN_INPUT_SELECTOR,
|
|
17
17
|
} from './internal/passkeys'
|
|
18
18
|
import { createRunGuard } from './internal/runGuard'
|
|
19
|
+
import { createStatusCache } from './internal/statusCache'
|
|
19
20
|
|
|
20
21
|
// Solo se exporta el composable (los helpers de ./internal no se auto-importan).
|
|
21
22
|
|
|
@@ -33,6 +34,9 @@ function supportsAutofill(): Promise<boolean> {
|
|
|
33
34
|
return autofillSupport
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/** Estado del interruptor de plataforma: una consulta por base durante la vida de la página. */
|
|
38
|
+
const statusCaches = createStatusCache()
|
|
39
|
+
|
|
36
40
|
function debug(...args: any[]) {
|
|
37
41
|
if (import.meta.dev) console.debug('[passkeys]', ...args)
|
|
38
42
|
}
|
|
@@ -51,12 +55,21 @@ export interface PasskeyItem {
|
|
|
51
55
|
* (/_auth/passkey/login) que sella la sesión solo si hay token.
|
|
52
56
|
* - Gestión propia: base 'auth' (tenant) o 'platform/auth' (cuenta de plataforma).
|
|
53
57
|
*
|
|
58
|
+
* Interruptor: el backend lo guarda en BD y lo expone en `GET auth/passkey/status`
|
|
59
|
+
* (o `platform/auth/passkey/status`). `usePasskeys({ platform: true })` consulta el de
|
|
60
|
+
* plataforma; sin opciones, el de tenant. `enabled` es false hasta saberlo y
|
|
61
|
+
* `available` = supported && enabled. Con el interruptor apagado, login/autocompletado/
|
|
62
|
+
* registro no hacen nada (el autocompletado devuelve null; el resto lanza un error legible).
|
|
63
|
+
* La administración por usuario (listForUser/revokeAll) sigue funcionando.
|
|
64
|
+
*
|
|
54
65
|
* Llamar durante el setup de un componente: `supported`/`autofillSupported` se
|
|
55
66
|
* resuelven en onMounted (false en SSR y en el primer render → sin hydration
|
|
56
67
|
* mismatch) y el autocompletado se libera en onBeforeUnmount.
|
|
57
68
|
*/
|
|
58
|
-
export function usePasskeys() {
|
|
69
|
+
export function usePasskeys({ platform: platformStatus = false }: { platform?: boolean } = {}) {
|
|
59
70
|
const api = useApi()
|
|
71
|
+
const statusBase = platformStatus ? 'platform/auth' : 'auth'
|
|
72
|
+
const statusCache = statusCaches.for(base => api.get(`${base}/passkey/status`))
|
|
60
73
|
const authStore = useAuthStore()
|
|
61
74
|
const { finishLogin } = useAuth()
|
|
62
75
|
|
|
@@ -64,10 +77,38 @@ export function usePasskeys() {
|
|
|
64
77
|
const autofillSupported = ref(false)
|
|
65
78
|
/** true una vez resuelto el soporte en el cliente (para no mostrar "no soportado" antes de tiempo). */
|
|
66
79
|
const ready = ref(false)
|
|
80
|
+
/** Interruptor de plataforma (false hasta conocerse y ante cualquier fallo). */
|
|
81
|
+
const enabled = ref(false)
|
|
82
|
+
/** Soporte del navegador Y interruptor encendido: lo que decide si se ofrece la función. */
|
|
83
|
+
const available = computed(() => supported.value && enabled.value)
|
|
84
|
+
|
|
85
|
+
/** Resuelve (con caché) el interruptor y lo refleja en `enabled`. */
|
|
86
|
+
async function ensureEnabled(): Promise<boolean> {
|
|
87
|
+
if (!import.meta.client) return false
|
|
88
|
+
enabled.value = await statusCache.get(statusBase)
|
|
89
|
+
return enabled.value
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Descarta la caché (tras guardar el interruptor en /platform) y lo vuelve a leer. */
|
|
93
|
+
async function refreshStatus(): Promise<boolean> {
|
|
94
|
+
statusCache.reset()
|
|
95
|
+
return ensureEnabled()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function disabledError() {
|
|
99
|
+
return Object.assign(new Error('El ingreso con passkey está desactivado.'), {
|
|
100
|
+
data: { message: 'El ingreso con passkey está desactivado.' },
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function assertEnabled() {
|
|
105
|
+
if (!(await ensureEnabled())) throw disabledError()
|
|
106
|
+
}
|
|
67
107
|
|
|
68
108
|
async function detectSupport() {
|
|
69
109
|
supported.value = browserSupportsWebAuthn()
|
|
70
110
|
autofillSupported.value = await supportsAutofill()
|
|
111
|
+
await ensureEnabled()
|
|
71
112
|
ready.value = true
|
|
72
113
|
}
|
|
73
114
|
|
|
@@ -133,6 +174,7 @@ export function usePasskeys() {
|
|
|
133
174
|
async function authenticate(platform: boolean, contexts: string[]) {
|
|
134
175
|
assertContexts(platform, contexts)
|
|
135
176
|
stopAutofill()
|
|
177
|
+
await assertEnabled()
|
|
136
178
|
const { key, options } = await fetchLoginOptions(platform)
|
|
137
179
|
const response = await startAuthentication({ optionsJSON: options })
|
|
138
180
|
return verify(platform, contexts, key, response)
|
|
@@ -162,6 +204,9 @@ export function usePasskeys() {
|
|
|
162
204
|
|
|
163
205
|
if (!(await supportsAutofill())) return null
|
|
164
206
|
if (!guard.isCurrent(id)) return null
|
|
207
|
+
// Interruptor apagado (o sin respuesta): silencio, sin pedir opciones.
|
|
208
|
+
if (!(await statusCache.get(platform ? 'platform/auth' : 'auth'))) return null
|
|
209
|
+
if (!guard.isCurrent(id)) return null
|
|
165
210
|
|
|
166
211
|
while (guard.isCurrent(id)) {
|
|
167
212
|
if (!document.querySelector(WEBAUTHN_INPUT_SELECTOR)) {
|
|
@@ -247,6 +292,7 @@ export function usePasskeys() {
|
|
|
247
292
|
}
|
|
248
293
|
|
|
249
294
|
async function register(name?: string, base = 'auth'): Promise<PasskeyItem> {
|
|
295
|
+
if (!(await statusCache.get(base))) throw disabledError()
|
|
250
296
|
const res: any = await api.post(`${base}/me/passkeys/options`)
|
|
251
297
|
if (!res?.key || !res?.options) throw sessionError()
|
|
252
298
|
const response = await startRegistration({ optionsJSON: res.options })
|
|
@@ -276,6 +322,10 @@ export function usePasskeys() {
|
|
|
276
322
|
supported,
|
|
277
323
|
autofillSupported,
|
|
278
324
|
ready,
|
|
325
|
+
enabled,
|
|
326
|
+
available,
|
|
327
|
+
ensureEnabled,
|
|
328
|
+
refreshStatus,
|
|
279
329
|
login,
|
|
280
330
|
loginPlatform,
|
|
281
331
|
startAutofill,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { createStatusCache } from '../statusCache'
|
|
3
|
+
|
|
4
|
+
describe('createStatusCache', () => {
|
|
5
|
+
it('consulta una sola vez por base', async () => {
|
|
6
|
+
const fetcher = vi.fn(async () => ({ enabled: true }))
|
|
7
|
+
const c = createStatusCache().for(fetcher)
|
|
8
|
+
expect(await Promise.all([c.get('auth'), c.get('auth')])).toEqual([true, true])
|
|
9
|
+
expect(fetcher).toHaveBeenCalledTimes(1)
|
|
10
|
+
await c.get('platform/auth')
|
|
11
|
+
expect(fetcher).toHaveBeenCalledTimes(2)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('fallo = desactivado y se reintenta después', async () => {
|
|
15
|
+
const fetcher = vi.fn()
|
|
16
|
+
.mockRejectedValueOnce(new Error('x'))
|
|
17
|
+
.mockResolvedValueOnce({ enabled: true })
|
|
18
|
+
const c = createStatusCache().for(fetcher)
|
|
19
|
+
expect(await c.get('auth')).toBe(false)
|
|
20
|
+
expect(await c.get('auth')).toBe(true)
|
|
21
|
+
expect(fetcher).toHaveBeenCalledTimes(2)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('respuesta nula o sin enabled es false', async () => {
|
|
25
|
+
const c = createStatusCache().for(async () => null)
|
|
26
|
+
expect(await c.get('auth')).toBe(false)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('reset fuerza una nueva consulta', async () => {
|
|
30
|
+
let enabled = false
|
|
31
|
+
const c = createStatusCache().for(async () => ({ enabled }))
|
|
32
|
+
expect(await c.get('auth')).toBe(false)
|
|
33
|
+
enabled = true
|
|
34
|
+
expect(await c.get('auth')).toBe(false)
|
|
35
|
+
c.reset('auth')
|
|
36
|
+
expect(await c.get('auth')).toBe(true)
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Caché de la promesa del estado (interruptor) de passkeys, por base ('auth' | 'platform/auth').
|
|
2
|
+
// Lógica pura (testeable en node): una consulta por base durante la vida de la página;
|
|
3
|
+
// un fallo cuenta como "desactivado" y NO se cachea (la próxima lectura reintenta).
|
|
4
|
+
|
|
5
|
+
export type StatusFetcher = (base: string) => Promise<{ enabled?: boolean } | null | undefined>
|
|
6
|
+
|
|
7
|
+
export interface StatusCache {
|
|
8
|
+
/** Estado de la base; nunca rechaza (fallo → false). */
|
|
9
|
+
get(base: string): Promise<boolean>
|
|
10
|
+
/** Olvida una base (o todas) para que la próxima lectura consulte de nuevo. */
|
|
11
|
+
reset(base?: string): void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createStatusCache(): { for(fetcher: StatusFetcher): StatusCache } {
|
|
15
|
+
const promises = new Map<string, Promise<boolean>>()
|
|
16
|
+
return {
|
|
17
|
+
for(fetcher) {
|
|
18
|
+
return {
|
|
19
|
+
get(base) {
|
|
20
|
+
let p = promises.get(base)
|
|
21
|
+
if (!p) {
|
|
22
|
+
const created: Promise<boolean> = (async () => {
|
|
23
|
+
try {
|
|
24
|
+
const res = await fetcher(base)
|
|
25
|
+
return res?.enabled === true
|
|
26
|
+
} catch {
|
|
27
|
+
if (promises.get(base) === created) promises.delete(base)
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
})()
|
|
31
|
+
p = created
|
|
32
|
+
promises.set(base, p)
|
|
33
|
+
}
|
|
34
|
+
return p
|
|
35
|
+
},
|
|
36
|
+
reset(base) {
|
|
37
|
+
if (base) promises.delete(base)
|
|
38
|
+
else promises.clear()
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
}
|
package/docs/passkeys.md
CHANGED
|
@@ -4,12 +4,17 @@ Ingreso con huella, rostro o llave de seguridad sobre `\Innertia\Passkeys` de in
|
|
|
4
4
|
|
|
5
5
|
## Requisitos (backend Laravel)
|
|
6
6
|
|
|
7
|
-
1.
|
|
8
|
-
2.
|
|
9
|
-
3. `
|
|
10
|
-
4.
|
|
7
|
+
1. `php artisan migrate` (crea la tabla de passkeys y la de configuración).
|
|
8
|
+
2. **Activación:** el ingreso con passkey viene **encendido por defecto** y se controla desde la consola `/platform` con `<Auth.PasskeySettings />` (interruptores "Ingreso con passkey" y "Permitir subdominios"; se guardan en BD). No hay variables de entorno. El producto registra las rutas en su grupo platform: `\Innertia\Passkeys\Routes::platformSettings('')`.
|
|
9
|
+
3. El front consulta `GET auth/passkey/status` (o `platform/auth/passkey/status`, con `usePasskeys({ platform: true })`) y solo ofrece la función si responde `{ enabled: true }`; el resultado se cachea por página y un fallo cuenta como desactivado. Con el interruptor apagado el backend responde 404 en login y autogestión, pero `users/{id}/passkeys` (administración) sigue funcionando para revocar.
|
|
10
|
+
4. El dominio (`rp_id`) y los orígenes se derivan de la URL del front; `<Auth.PasskeySettings />` los muestra en solo lectura.
|
|
11
11
|
5. El cache store de Laravel debe ser **compartido** entre instancias (Redis); las opciones de la ceremonia se guardan ahí.
|
|
12
12
|
|
|
13
|
+
```vue
|
|
14
|
+
<!-- pages/platform/settings/passkeys.vue -->
|
|
15
|
+
<template><Auth.PasskeySettings /></template>
|
|
16
|
+
```
|
|
17
|
+
|
|
13
18
|
Notas:
|
|
14
19
|
|
|
15
20
|
- Las cuentas de plataforma con cambio de contraseña forzado pendiente no pueden registrar una passkey hasta cambiarla.
|
|
@@ -86,7 +91,9 @@ El ingreso de plataforma siempre devuelve token (no hay `pending`). Si la cuenta
|
|
|
86
91
|
|
|
87
92
|
| Método | Uso |
|
|
88
93
|
|--------|-----|
|
|
89
|
-
| `
|
|
94
|
+
| `usePasskeys({ platform })` | `platform: true` usa el estado de `platform/auth/passkey/status`; por defecto el de tenant (`auth/passkey/status`) |
|
|
95
|
+
| `supported`, `autofillSupported`, `enabled`, `available`, `ready` | refs; `false` en SSR y en el primer render, se resuelven en `onMounted` (`ready` indica que ya se resolvió). `enabled` = interruptor de plataforma; `available` = `supported && enabled` |
|
|
96
|
+
| `ensureEnabled()`, `refreshStatus()` | lee el interruptor (con caché) / descarta la caché y lo relee (tras guardar en `/platform`) |
|
|
90
97
|
| `login({ contexts })`, `loginPlatform()` | ceremonia de ingreso (tenant / plataforma) |
|
|
91
98
|
| `startAutofill({ contexts, platform })`, `stopAutofill()`, `dispose()` | autocompletado (conditional UI); se libera solo al desmontar el componente que llamó a `usePasskeys()` |
|
|
92
99
|
| `list(base)`, `register(name?, base)`, `rename(id, name, base)`, `remove(id, base)` | gestión propia |
|