Implement passkey login functionality and enhance passkey support checks
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user