Major cleanup and refactoring of the backend (frontend not fully updated).

This commit is contained in:
Leo Vasanko
2025-08-01 12:32:27 -06:00
parent 0cfa622bf1
commit c5e5fe23e3
16 changed files with 451 additions and 920 deletions

View File

@@ -22,7 +22,12 @@ import AddCredentialView from '@/components/AddCredentialView.vue'
const store = useAuthStore()
onMounted(async () => {
// Check for device addition session first
// Was an error message passed in the URL?
const message = location.hash.substring(1)
if (message) {
store.showMessage(decodeURIComponent(message), 'error')
history.replaceState(null, '', location.pathname)
}
try {
await store.loadUserInfo()
} catch (error) {

View File

@@ -15,7 +15,7 @@
<script setup>
import { useAuthStore } from '@/stores/auth'
import { registerWithSession } from '@/utils/passkey'
import { registerCredential } from '@/utils/passkey'
import { ref, onMounted } from 'vue'
const authStore = useAuthStore()
@@ -25,9 +25,7 @@ const hasDeviceSession = ref(false)
onMounted(async () => {
try {
// Check if we have a device addition session
const response = await fetch('/auth/device-session-check', {
credentials: 'include'
})
const response = await fetch('/auth/device-session-check')
const data = await response.json()
if (data.device_addition_session) {
@@ -50,7 +48,7 @@ function register() {
authStore.isLoading = true
authStore.showMessage('Starting registration...', 'info')
registerWithSession().finally(() => {
registerCredential().finally(() => {
authStore.isLoading = false
}).then(() => {
authStore.showMessage('Passkey registered successfully!', 'success', 2000)

View File

@@ -46,7 +46,7 @@ const copyLink = async (event) => {
onMounted(async () => {
try {
const response = await fetch('/auth/create-device-link', { method: 'POST' })
const response = await fetch('/auth/create-link', { method: 'POST' })
const result = await response.json()
if (result.error) throw new Error(result.error)
@@ -63,7 +63,7 @@ onMounted(async () => {
})
}
} catch (error) {
console.error('Failed to fetch device link:', error)
console.error('Failed to create link:', error)
}
})
</script>

View File

@@ -33,10 +33,7 @@ export const useAuthStore = defineStore('auth', {
async setSessionCookie(sessionToken) {
const response = await fetch('/auth/set-session', {
method: 'POST',
headers: {
'Authorization': `Bearer ${sessionToken}`,
'Content-Type': 'application/json'
},
headers: {'Authorization': `Bearer ${sessionToken}`},
})
const result = await response.json()
if (result.error) {

View File

@@ -22,10 +22,7 @@ export async function registerCredential() {
return register('/auth/ws/add_credential')
}
export async function registerWithToken(token) {
return register('/auth/ws/add_device_credential', { token })
}
export async function registerWithSession() {
return register('/auth/ws/add_device_credential_session')
return register('/auth/ws/add_credential', { token })
}
export async function authenticateUser() {