I am using nuxt 3.11.1 and when I am trying to send my requests from the server side I’m yet seeing the requests in network tab which made me doubt if I am sending them correctly or not.
I have written a composable for sending my requests which is like this:
export async function useData(endpoint, params, method = "POST") {
const authToken = useCookie("Authorization-Token");
const options = {
method,
headers: {
"Client-Token": import.meta.env.VITE_API_CLIENT_TOKEN,
"Authorization-Token": authToken.value,
},
};
if (method === "POST") {
options.body = { ...params };
}
try {
const response = await $fetch(
`${import.meta.env.VITE_API_BASE_URL}/v1/${endpoint}`,
options
);
return response;
} catch (error) {
throw error;
}
}
And in my page components I try to use this composable as the following:
const authToken = useCookie("Authorization-Token");
if (authToken.value) {
await useAsyncData(async () => {
fetchData();
});
}
async function fetchData() {
try {
const response = await useData("URL");
}
if the authToken does not exist I create my token and send my requests from the client side, but I also store the token in the cookies and will use it for the future requests.
everything is working fine, but I’m seeing all of my requests in the network tab.