updated useFetch requests in onMounted to use

This commit is contained in:
Edward Tirado Jr 2025-04-19 14:48:48 -05:00
parent 592bbb1dd3
commit f7af5501da
4 changed files with 62 additions and 75 deletions

View file

@ -31,21 +31,19 @@ const updateLists = async function () {
headers["Authorization"] = `Token ${useCookie("token").value}`;
}
const { data, error } = await useFetch<MovieList[]>(
`${config.public.apiURL}/lists`,
{
method: "GET",
headers: headers,
},
);
if (error.value) {
if (error.value.statusCode === 401) {
navigateTo("/");
}
} else {
lists.value = data.value || [];
}
await $fetch<MovieList[]>(`${config.public.apiURL}/lists`, {
method: "GET",
headers: headers,
})
.then((data) => {
lists.value = data || [];
})
.catch((err) => {
if (err.statusCode === 401) {
useCookie("token").value = null;
navigateTo("/");
}
});
};
onMounted(() => {