Alpha v0.1.0 — KAPPA Hub inicial
- Auth con KAPPA (login + token Bearer) - Cliente HTTP para 10 endpoints (proyectos, HUs, bitácoras, planeaciones) - Dashboard multi-proyecto con concepto médico Teloprax - Calendario colombiano con 19 feriados (Ley Emiliani + Pascua) - Scheduler tipo cron con Dexie (reglas recurrentes, toasts, log) - Diseño marca Teloprax: Inter, Space Grotesk, #1A1A2E, rojo #E63946 - Stack: Vue 3 + TypeScript + Pinia + Vite + Bun
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { kappa } from '@/services/kappa-api'
|
||||
import type { KappaLoginPayload } from '@/types/kappa'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const token = ref<string | null>(localStorage.getItem('kappa_token'))
|
||||
const user = ref<{ name: string; email: string } | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
const isAuthenticated = computed(() => !!token.value)
|
||||
|
||||
async function login(payload: KappaLoginPayload) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const data = await kappa.login(payload)
|
||||
token.value = kappa['token'] // sync with the service instance
|
||||
user.value = {
|
||||
name: `${data.user?.first_name || ''} ${data.user?.last_name || ''}`.trim(),
|
||||
email: payload.email,
|
||||
}
|
||||
return true
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
return false
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
kappa.logout()
|
||||
token.value = null
|
||||
user.value = null
|
||||
}
|
||||
|
||||
return { token, user, loading, error, isAuthenticated, login, logout }
|
||||
})
|
||||
Reference in New Issue
Block a user