Frontend adjusted for the new API.

This commit is contained in:
Leo Vasanko 2025-08-01 13:16:10 -06:00
parent c5e5fe23e3
commit 8882d0672b
5 changed files with 15 additions and 43 deletions

View File

@ -16,29 +16,10 @@
<script setup> <script setup>
import { useAuthStore } from '@/stores/auth' import { useAuthStore } from '@/stores/auth'
import { registerCredential } from '@/utils/passkey' import { registerCredential } from '@/utils/passkey'
import { ref, onMounted } from 'vue' import { ref, computed } from 'vue'
const authStore = useAuthStore() const authStore = useAuthStore()
const hasDeviceSession = ref(false) const hasDeviceSession = computed(() => !!authStore.currentUser)
// Check existing session on app load
onMounted(async () => {
try {
// Check if we have a device addition session
const response = await fetch('/auth/device-session-check')
const data = await response.json()
if (data.device_addition_session) {
hasDeviceSession.value = true
} else {
authStore.showMessage('No device addition session found.', 'error')
authStore.currentView = 'login'
}
} catch (error) {
authStore.showMessage('Failed to check device addition session.', 'error')
authStore.currentView = 'login'
}
})
function register() { function register() {
if (!hasDeviceSession.value) { if (!hasDeviceSession.value) {

View File

@ -7,9 +7,9 @@
<h2>Device Addition Link</h2> <h2>Device Addition Link</h2>
<div class="qr-container"> <div class="qr-container">
<canvas id="qrCode" class="qr-code"></canvas> <canvas id="qrCode" class="qr-code"></canvas>
<p v-if="deviceLink.url"> <p v-if="url">
<a :href="deviceLink.url" id="deviceLinkText" @click="copyLink"> <a :href="url" id="deviceLinkText" @click="copyLink">
{{ deviceLink.url.replace(/^[^:]+:\/\//, '') }} {{ url.replace(/^[^:]+:\/\//, '') }}
</a> </a>
</p> </p>
</div> </div>
@ -33,12 +33,12 @@ import { useAuthStore } from '@/stores/auth'
import QRCode from 'qrcode/lib/browser' import QRCode from 'qrcode/lib/browser'
const authStore = useAuthStore() const authStore = useAuthStore()
const deviceLink = ref({ url: '', token: '' }) const url = ref(null)
const copyLink = async (event) => { const copyLink = async (event) => {
event.preventDefault() event.preventDefault()
if (deviceLink.value.url) { if (url.value) {
await navigator.clipboard.writeText(deviceLink.value.url) await navigator.clipboard.writeText(url.value)
authStore.showMessage('Link copied to clipboard!') authStore.showMessage('Link copied to clipboard!')
authStore.currentView = 'profile' authStore.currentView = 'profile'
} }
@ -50,15 +50,12 @@ onMounted(async () => {
const result = await response.json() const result = await response.json()
if (result.error) throw new Error(result.error) if (result.error) throw new Error(result.error)
deviceLink.value = { url.value = result.url
url: result.addition_link,
token: result.token
}
// Generate QR code // Generate QR code
const qrCodeElement = document.getElementById('qrCode') const qrCodeElement = document.getElementById('qrCode')
if (qrCodeElement) { if (qrCodeElement) {
QRCode.toCanvas(qrCodeElement, deviceLink.value.url, error => { QRCode.toCanvas(qrCodeElement, url.value, error => {
if (error) console.error('Failed to generate QR code:', error) if (error) console.error('Failed to generate QR code:', error)
}) })
} }

View File

@ -23,7 +23,7 @@
<div v-else> <div v-else>
<div <div
v-for="credential in authStore.currentCredentials" v-for="credential in authStore.currentCredentials"
:key="credential.credential_id" :key="credential.credential_uuid"
:class="['credential-item', { 'current-session': credential.is_current_session }]" :class="['credential-item', { 'current-session': credential.is_current_session }]"
> >
<div class="credential-header"> <div class="credential-header">
@ -49,7 +49,7 @@
</div> </div>
<div class="credential-actions"> <div class="credential-actions">
<button <button
@click="deleteCredential(credential.credential_id)" @click="deleteCredential(credential.credential_uuid)"
class="btn-delete-credential" class="btn-delete-credential"
:disabled="credential.is_current_session" :disabled="credential.is_current_session"
:title="credential.is_current_session ? 'Cannot delete current session credential' : ''" :title="credential.is_current_session ? 'Cannot delete current session credential' : ''"

View File

@ -80,14 +80,8 @@ export const useAuthStore = defineStore('auth', {
this.currentCredentials = result.credentials || [] this.currentCredentials = result.credentials || []
this.aaguidInfo = result.aaguid_info || {} this.aaguidInfo = result.aaguid_info || {}
}, },
async deleteCredential(credentialId) { async deleteCredential(uuid) {
const response = await fetch('/auth/delete-credential', { const response = await fetch(`/auth/credential/${uuid}`, {method: 'DELETE'})
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ credential_id: credentialId })
})
const result = await response.json() const result = await response.json()
if (result.error) throw new Error(`Server: ${result.error}`) if (result.error) throw new Error(`Server: ${result.error}`)

View File

@ -15,7 +15,7 @@ export async function register(url, options) {
} }
export async function registerUser(user_name) { export async function registerUser(user_name) {
return register('/auth/ws/register_new', { user_name }) return register('/auth/ws/register', { user_name })
} }
export async function registerCredential() { export async function registerCredential() {