feat: frontend für login, konto und benutzerverwaltung
- Login-Seite, Auth-Store und Router-Guard mit Weiterleitung nach dem Login - API-Client sendet X-CSRF-Token und reagiert auf 401 - Konto: Passwort ändern, angemeldete Geräte anzeigen und widerrufen - Benutzerverwaltung für Admins: anlegen, Rolle, aktiv, Passwort-Reset, löschen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e9585b395c
commit
4c2500797b
14 files changed
+873
-63
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { ApiError, api } from '@/api/client'
|
||||
import type { User } from '@/api/types'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const user = ref<User | null>(null)
|
||||
const loaded = ref(false)
|
||||
|
||||
const isAdmin = computed(() => user.value?.role === 'admin')
|
||||
|
||||
async function fetchMe(): Promise<void> {
|
||||
try {
|
||||
user.value = await api.get<User>('/auth/me')
|
||||
} catch (e) {
|
||||
if (!(e instanceof ApiError) || e.status !== 401) throw e
|
||||
user.value = null
|
||||
} finally {
|
||||
loaded.value = true
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureLoaded(): Promise<void> {
|
||||
if (!loaded.value) await fetchMe()
|
||||
}
|
||||
|
||||
async function login(username: string, password: string): Promise<void> {
|
||||
user.value = await api.post<User>('/auth/login', { username, password })
|
||||
loaded.value = true
|
||||
}
|
||||
|
||||
async function logout(): Promise<void> {
|
||||
try {
|
||||
await api.post('/auth/logout')
|
||||
} finally {
|
||||
clear()
|
||||
}
|
||||
}
|
||||
|
||||
function clear(): void {
|
||||
user.value = null
|
||||
}
|
||||
|
||||
return { user, loaded, isAdmin, fetchMe, ensureLoaded, login, logout, clear }
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { apiGet } from '@/api/client'
|
||||
import { api } from '@/api/client'
|
||||
|
||||
export interface Health {
|
||||
status: 'ok' | 'error'
|
||||
@@ -18,7 +18,7 @@ export const useHealthStore = defineStore('health', () => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
health.value = await apiGet<Health>('/health')
|
||||
health.value = await api.get<Health>('/health')
|
||||
} catch (e) {
|
||||
health.value = null
|
||||
error.value = e instanceof Error ? e.message : String(e)
|
||||
|
||||
Reference in new issue
Block a user