question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useFetch API breaks after page transition

See original GitHub issue

Hello,

I am facing an issue with useFetch() composable. I am calling my data like so :

// mypage.vue
const config = useRuntimeConfig()
const { data: images } = await useFetch<ImageKit[]>(
  'https://api.imagekit.io/v1/files',
  {
    method: 'GET',
    headers: {
      Accept: 'application/json',
      Authorization: 'Basic ' + config.IMAGEKIT_B64_API
    }
  }
)

When loading directly the URL http://localhost:3000/mypage the API is working as expected. However, when coming from another page, I have the following error : Safari Error I also have a this in Firefox Cors

I tried the solution posted here without success.

FYI I also tried this in `nuxt.config.ts :

routes: {
    '/': {
      prerender: true
    },
    '/*': {
      cors: true
    }
  }

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Sep 9, 2022

It should probably be:

- const { data: images } = useFetch<ImageKit[]>('api/imgkit')
+ const { data: images } = useFetch<ImageKit[]>('/api/imgkit')
1reaction
danielroecommented, Sep 9, 2022

Yes, that’s exactly the kind of thing you could do. Up to you how to implement it; it depends a bit on your use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useFetch
React hook for making isomorphic http requests.
Read more >
Error: fetch failed() error on nuxt 3 useFetch() initial API call
Error: fetch failed() Receving this error on initial useFetch() API call with page reloading and sometime it only return the result when we ......
Read more >
useFetch - VueUse
Reactive Fetch API provides the ability to abort requests, intercept requests before they are fired, automatically refetch requests when the url changes, ...
Read more >
Understanding common frustrations with React Hooks
Calling the useFetch Hook from an event handler breaks the rules of Hooks because you would break the order in which the Hooks...
Read more >
Build useFetch Custom React Hook to Fetch Data in 20 Minutes
In this video we will build a powerful Custom React Hook useFetch () that will help us to fetch the data from server...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found