Checkpoint, fixing reset token handling broken in earlier edits.

This commit is contained in:
Leo Vasanko
2025-08-06 09:55:14 -06:00
parent c42864794a
commit cf138d90c5
11 changed files with 392 additions and 170 deletions

View File

@@ -2,6 +2,7 @@
<div class="container">
<div class="view active">
<h1>🔑 Add Device Credential</h1>
<h3>👤 {{ authStore.currentUser.user_name }}</h3>
<button
class="btn-primary"
:disabled="authStore.isLoading"
@@ -15,13 +16,13 @@
<script setup>
import { useAuthStore } from '@/stores/auth'
import { computed } from 'vue'
import { registerCredential } from '@/utils/passkey'
import { ref, computed } from 'vue'
const authStore = useAuthStore()
const hasDeviceSession = computed(() => !!authStore.currentUser)
function register() {
async function register() {
if (!hasDeviceSession.value) {
authStore.showMessage('No valid device addition session', 'error')
return
@@ -29,18 +30,22 @@ function register() {
authStore.isLoading = true
authStore.showMessage('Starting registration...', 'info')
registerCredential().finally(() => {
authStore.isLoading = false
}).then(() => {
try {
const result = await registerCredential()
console.log("Result", result)
await authStore.setSessionCookie(result.session_token)
authStore.showMessage('Passkey registered successfully!', 'success', 2000)
authStore.currentView = 'profile'
}).catch((error) => {
} catch (error) {
console.error('Registration error:', error)
if (error.name === "NotAllowedError") {
authStore.showMessage('Registration cancelled', 'error')
} else {
authStore.showMessage(`Registration failed: ${error.message}`, 'error')
}
})
} finally {
authStore.isLoading = false
}
}
</script>

View File

@@ -46,13 +46,12 @@ export const useAuthStore = defineStore('auth', {
try {
const result = await registerUser(user_name)
await this.setSessionCookie(result.session_token)
this.currentUser = {
user_id: result.user_id,
user_name: user_name,
}
await this.setSessionCookie(result.session_token)
return result
} finally {
this.isLoading = false

View File

@@ -8,7 +8,6 @@ export async function register(url, options) {
const optionsJSON = await ws.receive_json()
const registrationResponse = await startRegistration({ optionsJSON })
ws.send_json(registrationResponse)
const result = await ws.receive_json()
ws.close()
return result;
@@ -31,7 +30,6 @@ export async function authenticateUser() {
const optionsJSON = await ws.receive_json()
const authResponse = await startAuthentication({ optionsJSON })
ws.send_json(authResponse)
const result = await ws.receive_json()
ws.close()
return result