@innertia-solutions/innertia-nuxt 0.1.80 → 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 CHANGED
@@ -6,6 +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. Se activa y desactiva desde `/platform` con `Auth.PasskeySettings` (sin variables de entorno). Ver `docs/passkeys.md`.
9
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).
10
11
 
11
12
  ### Fixed
@@ -153,7 +153,7 @@ const otherMobileApps = computed(() => {
153
153
  v-model="form.values.email"
154
154
  type="email"
155
155
  :disabled="processing"
156
- autocomplete="email"
156
+ autocomplete="username webauthn"
157
157
  placeholder="tu@correo.com"
158
158
  @blur="form.validate('email')"
159
159
  class="py-2.5 px-3 block w-full border rounded-lg sm:text-sm placeholder:text-slate-400 focus:ring-1 disabled:opacity-50 dark:bg-transparent dark:text-slate-300"
@@ -0,0 +1,105 @@
1
+ <script setup>
2
+ import { IconFingerprint } from '@tabler/icons-vue'
3
+
4
+ // Botón "Ingresar con huella o passkey" para cualquier login.
5
+ // - contexts: lista ordenada (login tenant). OBLIGATORIA salvo con `platform`:
6
+ // sin contexts el composable lanza 'PasskeyButton requiere contexts' antes de
7
+ // cualquier ceremonia (el backend exige al menos uno).
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.
11
+ // - autofill: además arranca el autocompletado (el campo de correo del form
12
+ // debe tener autocomplete="username webauthn"; sin ese input no arranca).
13
+ // Emite success(data) con el body del BFF (data.context; data.tenantDestination
14
+ // en modo open), pending(data) si hay un paso previo (cambio forzado de clave) o
15
+ // error(message, originalError). Las cancelaciones no emiten nada.
16
+ const props = defineProps({
17
+ contexts: {
18
+ type: Array,
19
+ default: () => [],
20
+ // Nota: la validación real (contexts requeridos sin `platform`) ocurre al
21
+ // iniciar la ceremonia, porque depende de otra prop.
22
+ validator: v => Array.isArray(v) && v.every(c => typeof c === 'string'),
23
+ },
24
+ platform: { type: Boolean, default: false },
25
+ autofill: { type: Boolean, default: true },
26
+ label: { type: String, default: 'Ingresar con huella o passkey' },
27
+ })
28
+ const emit = defineEmits(['success', 'pending', 'error'])
29
+
30
+ const passkeys = usePasskeys({ platform: props.platform })
31
+ const loading = ref(false)
32
+ const error = ref('')
33
+ let mounted = false
34
+
35
+ function handle(data) {
36
+ if (!data) return false
37
+ if (data.user) {
38
+ emit('success', data)
39
+ return true
40
+ }
41
+ emit('pending', data)
42
+ return true
43
+ }
44
+
45
+ function fail(e) {
46
+ error.value = passkeys.errorMessage(e)
47
+ emit('error', error.value, e)
48
+ }
49
+
50
+ async function click() {
51
+ error.value = ''
52
+ loading.value = true
53
+ let done = false
54
+ try {
55
+ // login() invalida el autocompletado antes de su propia ceremonia.
56
+ done = handle(props.platform ? await passkeys.loginPlatform() : await passkeys.login({ contexts: props.contexts }))
57
+ } catch (e) {
58
+ if (!passkeys.isDismissed(e)) fail(e)
59
+ } finally {
60
+ loading.value = false
61
+ }
62
+ // Tras un ingreso exitoso no se reanuda; solo tras fallo/cancelación y si sigue montado.
63
+ if (!done && mounted) startAutofill()
64
+ }
65
+
66
+ async function startAutofill() {
67
+ if (!props.autofill || !mounted) return
68
+ try {
69
+ const done = handle(await passkeys.startAutofill({ contexts: props.contexts, platform: props.platform }))
70
+ if (done) return
71
+ } catch (e) {
72
+ // Solo llegan aquí errores tras elegir una passkey (BFF) o de configuración (ya avisado por consola).
73
+ if (passkeys.isContextsError(e)) return
74
+ if (!passkeys.isDismissed(e)) fail(e)
75
+ // Falló la verificación: se vuelve a ofrecer el autocompletado.
76
+ if (mounted && !loading.value) startAutofill()
77
+ }
78
+ }
79
+
80
+ onMounted(() => {
81
+ mounted = true
82
+ startAutofill()
83
+ })
84
+ onBeforeUnmount(() => {
85
+ mounted = false
86
+ passkeys.dispose()
87
+ })
88
+ </script>
89
+
90
+ <template>
91
+ <div v-if="passkeys.available.value" class="space-y-2">
92
+ <button
93
+ type="button"
94
+ :disabled="loading"
95
+ :aria-busy="loading ? 'true' : 'false'"
96
+ class="inline-flex w-full items-center justify-center gap-2 rounded-control border border-card-line bg-card px-4 py-2.5 text-sm font-medium text-foreground hover:bg-muted-hover focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/30 disabled:cursor-not-allowed disabled:opacity-60 transition-colors"
97
+ @click="click"
98
+ >
99
+ <span v-if="loading" class="size-4 animate-spin rounded-full border-2 border-current/30 border-t-current" aria-hidden="true" />
100
+ <IconFingerprint v-else class="size-4" aria-hidden="true" />
101
+ {{ label }}
102
+ </button>
103
+ <p v-if="error" class="text-xs text-red-500" role="alert">{{ error }}</p>
104
+ </div>
105
+ </template>
@@ -0,0 +1,78 @@
1
+ <script setup>
2
+ import { IconFingerprint, IconX } from '@tabler/icons-vue'
3
+ import { shouldShowPasskeyInvite, inviteStorageKey } from '../../composables/usePasskeys/internal/passkeys'
4
+
5
+ // Aviso discreto tras ingresar con contraseña: "Ingresa con tu huella la próxima
6
+ // vez". Una vez por usuario y dispositivo (localStorage). base: 'auth' | 'platform/auth'.
7
+ const props = defineProps({
8
+ base: { type: String, default: 'auth' },
9
+ })
10
+
11
+ const passkeys = usePasskeys({ platform: props.base === 'platform/auth' })
12
+ const authStore = useAuthStore()
13
+ const toast = useToast()
14
+ const visible = ref(false)
15
+ const saving = ref(false)
16
+
17
+ const userId = computed(() => authStore.user?.id)
18
+
19
+ function dismissed() {
20
+ try { return localStorage.getItem(inviteStorageKey(userId.value)) === 'dismissed' } catch { return true }
21
+ }
22
+
23
+ function dismiss() {
24
+ try { localStorage.setItem(inviteStorageKey(userId.value), 'dismissed') } catch {}
25
+ visible.value = false
26
+ }
27
+
28
+ // usePasskeys resuelve `supported` en su propio onMounted, que corre antes que este.
29
+ onMounted(async () => {
30
+ if (!userId.value || !passkeys.supported.value) return
31
+ // Interruptor apagado: ni se consulta la lista.
32
+ if (!(await passkeys.ensureEnabled())) return
33
+ let hasPasskeys = true
34
+ try { hasPasskeys = (await passkeys.list(props.base)).length > 0 } catch { return }
35
+ visible.value = shouldShowPasskeyInvite({
36
+ supported: passkeys.supported.value,
37
+ enabled: passkeys.enabled.value,
38
+ dismissed: dismissed(),
39
+ hasPasskeys,
40
+ loggedInWithPasskey: passkeys.loggedInWithPasskey(),
41
+ })
42
+ })
43
+
44
+ async function activate() {
45
+ saving.value = true
46
+ try {
47
+ await passkeys.register(undefined, props.base)
48
+ toast.success('Listo: la próxima vez ingresa con tu huella.')
49
+ dismiss()
50
+ } catch (e) {
51
+ if (!passkeys.isCancel(e)) toast.error(passkeys.errorMessage(e))
52
+ } finally {
53
+ saving.value = false
54
+ }
55
+ }
56
+ </script>
57
+
58
+ <template>
59
+ <div
60
+ v-if="visible"
61
+ class="flex items-center gap-3 rounded-card border border-card-line bg-card px-4 py-3 shadow-sm"
62
+ role="status"
63
+ >
64
+ <IconFingerprint class="size-5 shrink-0 text-primary" aria-hidden="true" />
65
+ <p class="flex-1 text-sm text-foreground">
66
+ Ingresa con tu huella la próxima vez, sin contraseña.
67
+ </p>
68
+ <App.Button text="Activar" severity="primary" size="sm" :loading="saving" @click="activate" />
69
+ <button
70
+ type="button"
71
+ class="rounded-control p-1 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/30"
72
+ aria-label="Ahora no, cerrar la invitación a usar passkey"
73
+ @click="dismiss"
74
+ >
75
+ <IconX class="size-4" aria-hidden="true" />
76
+ </button>
77
+ </div>
78
+ </template>
@@ -0,0 +1,176 @@
1
+ <script setup>
2
+ import { IconFingerprint, IconPencil, IconTrash, IconPlus } from '@tabler/icons-vue'
3
+
4
+ // Gestión de las passkeys propias (perfil › Seguridad). base: 'auth' | 'platform/auth'.
5
+ const props = defineProps({
6
+ base: { type: String, default: 'auth' },
7
+ })
8
+
9
+ const passkeys = usePasskeys({ platform: props.base === 'platform/auth' })
10
+ const toast = useToast()
11
+ const { confirm } = useModal()
12
+ const items = ref([])
13
+ const loading = ref(true)
14
+ const loadError = ref('')
15
+ const adding = ref(false)
16
+ const editingId = ref(null)
17
+ const editName = ref('')
18
+ const editInput = ref(null)
19
+
20
+ const fmt = (iso) => iso ? new Date(iso).toLocaleDateString('es-CL', { day: 'numeric', month: 'short', year: 'numeric' }) : 'Nunca'
21
+
22
+ async function load() {
23
+ loading.value = true
24
+ loadError.value = ''
25
+ if (!(await passkeys.ensureEnabled())) {
26
+ loading.value = false
27
+ return
28
+ }
29
+ try {
30
+ items.value = await passkeys.list(props.base)
31
+ } catch (e) {
32
+ loadError.value = passkeys.errorMessage(e)
33
+ } finally {
34
+ loading.value = false
35
+ }
36
+ }
37
+
38
+ async function add() {
39
+ adding.value = true
40
+ try {
41
+ await passkeys.register(undefined, props.base)
42
+ toast.success('Passkey agregada.')
43
+ await load()
44
+ } catch (e) {
45
+ if (!passkeys.isCancel(e)) toast.error(passkeys.errorMessage(e))
46
+ } finally {
47
+ adding.value = false
48
+ }
49
+ }
50
+
51
+ async function startEdit(item) {
52
+ editingId.value = item.id
53
+ editName.value = item.name
54
+ await nextTick()
55
+ // ref dentro de v-for → arreglo
56
+ const el = Array.isArray(editInput.value) ? editInput.value[0] : editInput.value
57
+ el?.focus()
58
+ el?.select()
59
+ }
60
+
61
+ // Esc cancela sin guardar: se suelta la edición ANTES del blur que provoca
62
+ // desmontar el input, así saveEdit (por blur) ve que ya no se edita y no guarda.
63
+ function cancelEdit() {
64
+ editingId.value = null
65
+ }
66
+
67
+ async function saveEdit(item) {
68
+ // Enter + blur: solo la primera llamada guarda (evita doble PATCH).
69
+ if (editingId.value !== item.id) return
70
+ editingId.value = null
71
+ const name = editName.value.trim()
72
+ if (!name || name === item.name) return
73
+ const previous = item.name
74
+ item.name = name
75
+ try {
76
+ await passkeys.rename(item.id, name, props.base)
77
+ } catch (e) {
78
+ item.name = previous
79
+ toast.error(passkeys.errorMessage(e))
80
+ }
81
+ }
82
+
83
+ async function removeItem(item) {
84
+ const ok = await confirm({ severity: 'danger', message: `¿Eliminar la passkey "${item.name}"? Ya no podrás ingresar con ella.` })
85
+ if (!ok) return
86
+ try {
87
+ await passkeys.remove(item.id, props.base)
88
+ items.value = items.value.filter(i => i.id !== item.id)
89
+ toast.success('Passkey eliminada.')
90
+ } catch (e) {
91
+ toast.error(passkeys.errorMessage(e))
92
+ }
93
+ }
94
+
95
+ onMounted(load)
96
+ </script>
97
+
98
+ <template>
99
+ <div class="rounded-card border border-card-line bg-card">
100
+ <div class="flex items-center justify-between gap-3 border-b border-card-line px-5 py-4">
101
+ <div>
102
+ <h3 class="text-sm font-semibold text-foreground">Passkeys</h3>
103
+ <p class="mt-0.5 text-xs text-muted-foreground">Ingresa con tu huella, rostro o PIN del dispositivo, sin contraseña.</p>
104
+ </div>
105
+ <App.Button
106
+ v-if="passkeys.ready.value && passkeys.available.value"
107
+ text="Agregar en este dispositivo"
108
+ :icon="IconPlus"
109
+ severity="primary"
110
+ size="sm"
111
+ :loading="adding"
112
+ @click="add"
113
+ />
114
+ </div>
115
+
116
+ <div v-if="!passkeys.ready.value" class="px-5 py-6 text-sm text-muted-foreground">Cargando…</div>
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
+
122
+ <p v-else-if="!passkeys.supported.value" class="px-5 py-4 text-sm text-muted-foreground">
123
+ Este navegador no permite usar passkeys.
124
+ </p>
125
+
126
+ <div v-else-if="loading" class="px-5 py-6 text-sm text-muted-foreground">Cargando…</div>
127
+
128
+ <div v-else-if="loadError" class="flex items-center justify-between gap-3 px-5 py-6" role="alert">
129
+ <p class="text-sm text-red-600">{{ loadError }}</p>
130
+ <App.Button text="Reintentar" size="sm" @click="load" />
131
+ </div>
132
+
133
+ <p v-else-if="!items.length" class="px-5 py-6 text-sm text-muted-foreground">
134
+ Aún no tienes passkeys. Agrega una para ingresar con tu huella.
135
+ </p>
136
+
137
+ <ul v-else class="divide-y divide-card-line">
138
+ <li v-for="item in items" :key="item.id" class="flex items-center gap-3 px-5 py-3">
139
+ <IconFingerprint class="size-5 shrink-0 text-muted-foreground" aria-hidden="true" />
140
+ <div class="min-w-0 flex-1">
141
+ <input
142
+ v-if="editingId === item.id"
143
+ ref="editInput"
144
+ v-model="editName"
145
+ maxlength="120"
146
+ :aria-label="`Nuevo nombre para la passkey ${item.name}`"
147
+ class="w-full rounded-control border border-card-line bg-transparent px-2 py-1 text-sm text-foreground focus:border-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/30"
148
+ @keydown.enter.prevent="saveEdit(item)"
149
+ @keydown.esc.prevent.stop="cancelEdit"
150
+ @blur="saveEdit(item)"
151
+ />
152
+ <p v-else class="truncate text-sm font-medium text-foreground">{{ item.name }}</p>
153
+ <p class="text-xs text-muted-foreground">
154
+ <span v-if="item.provider">{{ item.provider }} · </span>Creada {{ fmt(item.created_at) }} · Último uso {{ fmt(item.last_used_at) }}
155
+ </p>
156
+ </div>
157
+ <button
158
+ type="button"
159
+ class="rounded-control p-1 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/30"
160
+ :aria-label="`Renombrar passkey ${item.name}`"
161
+ @click="startEdit(item)"
162
+ >
163
+ <IconPencil class="size-4" aria-hidden="true" />
164
+ </button>
165
+ <button
166
+ type="button"
167
+ class="rounded-control p-1 text-muted-foreground hover:text-red-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-red-500/30"
168
+ :aria-label="`Eliminar passkey ${item.name}`"
169
+ @click="removeItem(item)"
170
+ >
171
+ <IconTrash class="size-4" aria-hidden="true" />
172
+ </button>
173
+ </li>
174
+ </ul>
175
+ </div>
176
+ </template>
@@ -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>
@@ -0,0 +1,72 @@
1
+ <script setup>
2
+ import { IconFingerprint } from '@tabler/icons-vue'
3
+
4
+ // Para administradores: passkeys de un usuario (cantidad, último uso) y
5
+ // "Revocar todas" (dispositivo perdido, funcionario que se va).
6
+ const props = defineProps({
7
+ userId: { type: [String, Number], required: true },
8
+ })
9
+
10
+ const passkeys = usePasskeys()
11
+ const toast = useToast()
12
+ const { confirm } = useModal()
13
+ const items = ref([])
14
+ const loading = ref(true)
15
+ const loadError = ref('')
16
+ const revoking = ref(false)
17
+
18
+ const lastUsed = computed(() => {
19
+ const dates = items.value.map(i => i.last_used_at).filter(Boolean).sort()
20
+ return dates.length ? new Date(dates[dates.length - 1]).toLocaleString('es-CL', { dateStyle: 'medium', timeStyle: 'short' }) : null
21
+ })
22
+
23
+ async function load() {
24
+ loading.value = true
25
+ loadError.value = ''
26
+ try {
27
+ items.value = await passkeys.listForUser(props.userId)
28
+ } catch (e) {
29
+ items.value = []
30
+ loadError.value = passkeys.errorMessage(e)
31
+ } finally {
32
+ loading.value = false
33
+ }
34
+ }
35
+
36
+ async function revoke() {
37
+ const ok = await confirm({ severity: 'danger', message: 'Se revocarán todas las passkeys de este usuario. Tendrá que ingresar con su contraseña. ¿Continuar?' })
38
+ if (!ok) return
39
+ revoking.value = true
40
+ try {
41
+ const n = await passkeys.revokeAll(props.userId)
42
+ toast.success(n === 1 ? '1 passkey revocada.' : `${n} passkeys revocadas.`)
43
+ await load()
44
+ } catch (e) {
45
+ toast.error(passkeys.errorMessage(e))
46
+ } finally {
47
+ revoking.value = false
48
+ }
49
+ }
50
+
51
+ watch(() => props.userId, load)
52
+ onMounted(load)
53
+ </script>
54
+
55
+ <template>
56
+ <div class="flex items-center gap-3 rounded-card border border-card-line bg-card px-5 py-4">
57
+ <IconFingerprint class="size-5 shrink-0 text-muted-foreground" aria-hidden="true" />
58
+ <div class="min-w-0 flex-1">
59
+ <p class="text-sm font-medium text-foreground">Passkeys</p>
60
+ <p class="text-xs text-muted-foreground">
61
+ <template v-if="loading">Cargando…</template>
62
+ <span v-else-if="loadError" class="text-red-600" role="alert">{{ loadError }}</span>
63
+ <template v-else-if="!items.length">No tiene passkeys.</template>
64
+ <template v-else>
65
+ {{ items.length === 1 ? '1 passkey' : `${items.length} passkeys` }}<template v-if="lastUsed"> · último uso {{ lastUsed }}</template>
66
+ </template>
67
+ </p>
68
+ </div>
69
+ <App.Button v-if="loadError" text="Reintentar" size="sm" @click="load" />
70
+ <App.Button v-else-if="items.length" text="Revocar todas" severity="danger" size="sm" :loading="revoking" @click="revoke" />
71
+ </div>
72
+ </template>
@@ -14,6 +14,10 @@ export function useAuth() {
14
14
  */
15
15
  async function performLogin(context, email, password, remember = false) {
16
16
  authStore.rememberUser = remember
17
+ // Un ingreso con contraseña borra la marca de "ingresó con passkey" (la invitación vuelve a aparecer).
18
+ if (import.meta.client) {
19
+ try { sessionStorage.removeItem('innertia:logged-in-with-passkey') } catch {}
20
+ }
17
21
  // Sella la sesión en el server (Nitro). Devuelve user+contexts, SIN token.
18
22
  const data = await $fetch('/_auth/login', {
19
23
  method: 'POST',
@@ -101,6 +105,10 @@ export function useAuth() {
101
105
  async function logout() {
102
106
  try { await $fetch('/_auth/logout', { method: 'POST' }) } catch { /* best-effort */ }
103
107
  queryClient.clear()
108
+ // La marca "ingresó con passkey" es de la sesión que termina.
109
+ if (import.meta.client) {
110
+ try { sessionStorage.removeItem('innertia:logged-in-with-passkey') } catch {}
111
+ }
104
112
  authStore.logout() // limpia el state en memoria
105
113
  organizationStore.reset()
106
114
  // En open, limpiar también el tenant seleccionado
@@ -120,5 +128,5 @@ export function useAuth() {
120
128
  return data.url ?? data
121
129
  }
122
130
 
123
- return { performLogin, verifyOtp, changeForcedPassword, fetchMe, logout, getOauthRedirectUrl }
131
+ return { performLogin, verifyOtp, changeForcedPassword, finishLogin, fetchMe, logout, getOauthRedirectUrl }
124
132
  }