useFetch requests are doubled

I can understand that checkSession from auth.global runs twice because client and server, but after clicking sign Out I get first signOut, double checkSession and then it repeats again. However worst part is when I try to sign In again, it runs signOut twice again
No description
No description
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @SaaikaHatak. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, it appears that the issue of doubled useFetch requests is a known behavior in Nuxt 3, especially when dealing with layouts and server-side rendering. Here's what we can understand from the available information: 1. Double fetching can occur when useFetch is used without proper handling, causing requests to be made both on the server and client side during hydration Source (https://nuxt.com/docs/getting-started/data-fetching#the-need-for-usefetch-and-useasyncdata). 2. This issue can be more pronounced when using layouts, as mentioned in a GitHub issue Source (https://github.com/nuxt/nuxt/issues/13369). To address your specific situation: 1. The double checkSession after signing out could be related to the server-side rendering and client-side hydration process. 2. The repeated sign-out attempts might be caused by a similar issue, where the action is triggered both on the server and client side. To mitigate these issues, you could try the following: 1. Use useAsyncData or useFetch with proper caching strategies to prevent double fetching Source (https://nuxt.com/docs/api/utils/dollarfetch). 2. Consider adding a key to the useFetch call to control when it should refetch, as suggested in a GitHub comment:
useFetch('/api/data', {
key: Date.now().toString()
})

useFetch('/api/data', {
key: Date.now().toString()
})

Source (https://github.com/nuxt/nuxt/issues/29378) 3. If the issue persists, you might want to investigate if there are any watch dependencies or reactive properties causing unnecessary re-fetches. 4. In some cases, disabling SSR for specific components or pages might help, but this should be done cautiously as it affects SEO and initial load performance. If these suggestions don't resolve the issue, you may need to provide a minimal reproduction of your specific setup for further investigation. The Nuxt team often requests such reproductions to diagnose and fix similar problems Source (https://github.com/nuxt/nuxt/issues/29378). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@149470866156158976> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Want results from more Discord servers?
Add your server