OSS-BSS-Field-Dispatch/src/stores/auth.js
louispaulb 1b0fc89304 Initial commit — OSS/BSS Field Dispatch app
Current state: custom CSS + vanilla Vue components
Architecture: modular with composables, provide/inject pattern
Ready for progressive migration to Quasar native components

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 14:11:40 -04:00

40 lines
1.4 KiB
JavaScript

// ── Auth store ───────────────────────────────────────────────────────────────
// Holds current session state. Calls api/auth.js only.
// To change the auth method: edit api/auth.js. This store stays the same.
// ─────────────────────────────────────────────────────────────────────────────
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { login, logout, getLoggedUser } from 'src/api/auth'
export const useAuthStore = defineStore('auth', () => {
const user = ref(null) // email string when logged in, null when guest
const loading = ref(false)
const error = ref('')
async function checkSession () {
loading.value = true
user.value = await getLoggedUser()
loading.value = false
}
async function doLogin (usr, pwd) {
loading.value = true
error.value = ''
try {
await login(usr, pwd)
user.value = usr
} catch (e) {
error.value = e.message || 'Erreur de connexion'
} finally {
loading.value = false
}
}
async function doLogout () {
await logout()
user.value = null
}
return { user, loading, error, checkSession, doLogin, doLogout }
})