entorno de desarrollo listo

This commit is contained in:
2025-10-05 15:56:42 -06:00
parent 4a1f153417
commit 0380f69f1b
7 changed files with 165 additions and 14 deletions

View File

@@ -0,0 +1,38 @@
export interface AuthUser {
username: string | null
email: string | null
name: string | null
uid: string | null
groups: string[]
authenticated: boolean
}
export const useAuth = () => {
const user = useState<AuthUser | null>('auth-user', () => null)
const loading = useState<boolean>('auth-loading', () => false)
const fetchUser = async () => {
loading.value = true
try {
const data = await $fetch<AuthUser>('/api/auth/user')
user.value = data
} catch (error) {
console.error('Error fetching user:', error)
user.value = null
} finally {
loading.value = false
}
}
const logout = () => {
// Authentik maneja el logout, redirigir a la URL de logout
window.location.href = '/outpost.goauthentik.io/sign_out'
}
return {
user: readonly(user),
loading: readonly(loading),
fetchUser,
logout
}
}