import { ref, computed } from 'vue' const _token = ref(localStorage.getItem('auth_token') || null) const _username = ref(localStorage.getItem('auth_username') || null) const _mustChange = ref(localStorage.getItem('auth_mustchange') === 'true') export const isAuthenticated = computed(() => !!_token.value) export const currentUsername = computed(() => _username.value) export const mustChangePassword = computed(() => _mustChange.value) export function setAuth(token, username, mustChange = false) { _token.value = token _username.value = username _mustChange.value = mustChange localStorage.setItem('auth_token', token) localStorage.setItem('auth_username', username) localStorage.setItem('auth_mustchange', String(mustChange)) } export function clearAuth() { _token.value = null _username.value = null _mustChange.value = false localStorage.removeItem('auth_token') localStorage.removeItem('auth_username') localStorage.removeItem('auth_mustchange') } export function getToken() { return _token.value }