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