Fetch Data even on page reload using custom Fetch Composable
I am trying to fetch data in a page. I am using a custom Fetch composable. But the fetch seems only to work when I navigate to the page using route links. This page uses a middleware but I think this is not the main concern
composable useAuthFetch:
5 Replies
I also use a custom composable, the data is still retrieved. Can you say more? I don't see xhr requests during a reload but the data is still obtained
Thanks for reading my question, I also don't see a XHR request being made, except the data is not obtained. I am fetching (
/vendor/me
) something from my node.js server.
My useAuthFetch is just composable which sets a JWT token as the auth bearer token.your auth part is in the useNuxtApp().$autFetch ?
Here's my custom fetch, made for interact with a Laravel API. Maybe you can take it and adapt with your auth logic.
thanks for the example, I've managed to fix my problem. I was retrieving a value that did not exist, so the useAuthFetch silently failed π
If somebody knows how I can stop this from silently failing without a try & catch please let me know π I also tried the
onRequestError
or onResponseError
.You see no requests on reload (or first load for that matter) because the requests are made server side not on the client. Try to log anything in your console.log and you'll see it in the dev server terminal. For the errors you can destruct
error
from your custom useFetch just like you're destrctring data
and pending