Implement passkey login functionality and enhance passkey support checks
All checks were successful
Code Analysis and Production Deploy / analyze (push) Has been skipped
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Successful in 2m7s

This commit is contained in:
Torsten Schulz (local)
2026-05-15 13:20:09 +02:00
parent dba2747883
commit 8ae7dcdbf1
4 changed files with 119 additions and 16 deletions

View File

@@ -54,15 +54,21 @@ export const useAuthStore = defineStore('auth', {
return response
},
async passkeyLogin() {
async passkeyLogin(email = '') {
// Client-only
if (typeof window === 'undefined' || !window.PublicKeyCredential) {
if (typeof window === 'undefined' || !window.PublicKeyCredential || !window.isSecureContext) {
throw new Error('Passkeys werden von diesem Browser nicht unterstützt.')
}
const { options } = await $fetch('/api/auth/passkeys/authentication-options', { method: 'POST' })
const normalizedEmail = String(email || '').trim().toLowerCase()
const { options } = await $fetch('/api/auth/passkeys/authentication-options', {
method: 'POST',
body: normalizedEmail ? { email: normalizedEmail } : {}
})
const mod = await import('@simplewebauthn/browser')
const credential = await mod.startAuthentication(options)
const credential = await mod.startAuthentication({ optionsJSON: options })
const response = await $fetch('/api/auth/passkeys/login', {
method: 'POST',
@@ -83,7 +89,7 @@ export const useAuthStore = defineStore('auth', {
this.user = null
this.roles = []
this.role = null
} catch (_error) {
} catch (error) {
console.error('Logout fehlgeschlagen:', error)
throw error
}