feat: add authenticated admin shell
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-08 22:25:29 -04:00
parent a21d1ae854
commit 86c60f9381
10 changed files with 182 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
import { computed, ref } from 'vue';
import { getCurrentPrincipal, login, logout } from '@/services/auth-service.js';
const principal = ref(null);
const isLoading = ref(false);
const error = ref(null);
function csrfToken() {
return document.cookie.split('; ').find((value) => value.startsWith('pokemon_inventory_csrf='))?.split('=')[1] ?? '';
}
export function useAuth() {
const isAuthenticated = computed(() => Boolean(principal.value));
async function load() {
isLoading.value = true;
try { principal.value = await getCurrentPrincipal(); }
catch { principal.value = null; }
finally { isLoading.value = false; }
}
async function signIn(email, password) {
error.value = null;
isLoading.value = true;
try { await login(email, password); await load(); }
catch (requestError) { error.value = requestError; throw requestError; }
finally { isLoading.value = false; }
}
async function signOut() {
await logout(csrfToken());
principal.value = null;
}
return { principal, isAuthenticated, isLoading, error, load, signIn, signOut };
}