33 lines
579 B
TypeScript
33 lines
579 B
TypeScript
import { ref } from "vue"
|
|
import { isUnauthorized } from "~/utils/auth"
|
|
|
|
export function useServers() {
|
|
const servers = ref([])
|
|
const loading = ref(false)
|
|
const error = ref("")
|
|
|
|
const { apiFetch } = useApi()
|
|
|
|
async function loadServers() {
|
|
loading.value = true
|
|
error.value = ""
|
|
|
|
const result = await apiFetch("/servers")
|
|
|
|
if (isUnauthorized(result)) {
|
|
loading.value = false
|
|
return result
|
|
}
|
|
|
|
servers.value = result
|
|
loading.value = false
|
|
return result
|
|
}
|
|
|
|
return {
|
|
servers,
|
|
loading,
|
|
error,
|
|
loadServers
|
|
}
|
|
}
|