feat: Initialize project with configuration files and basic structure

This commit is contained in:
Thibault Pouch
2026-05-01 10:57:26 +02:00
parent 268f7949dc
commit c2920dbbdc
11 changed files with 151 additions and 0 deletions

31
stores/auth.ts Normal file
View File

@@ -0,0 +1,31 @@
import { defineStore } from 'pinia';
interface AuthUser {
id: string;
email: string;
username: string;
role: 'ADMIN' | 'DEV' | 'MEMBER';
}
export const useAuthStore = defineStore('auth', () => {
const user = ref<AuthUser | null>(null);
const token = ref<string | null>(null);
const isAuthenticated = computed(() => !!token.value);
async function login(credentials: { email: string; password: string }) {
const config = useRuntimeConfig();
const data = await $fetch<{ token: string; user: AuthUser }>(
`${config.public.apiBaseUrl}/auth/login`,
{ method: 'POST', body: credentials },
);
token.value = data.token;
user.value = data.user;
}
function logout() {
token.value = null;
user.value = null;
}
return { user, token, isAuthenticated, login, logout };
});