You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a situation where post data is fetched on initial page load in Nuxt 3 with SSR enabled. The post endpoint displays different posts based on auth vs unauth users. This works fine in most cases except when a user goes to the page during a token refresh.
During a token refresh, my app gets the new token and updates the authStore user and isAuth flag. The PostList component would watch for changes on the isAuth flag, but the problem is the watch function doesn't pick up the flag change in this case, so the Post shows the unauth version of posts.
Post Component code:
const { refetch } = await fetchPosts(params)
// This watch doesn't get triggered during the authStore update in refresh token logic, so force it to refetch the data using immediate set to true
watch(isAuth, async () => {
const { error, data } = await refetch();
// Handle refetch logic
}, { immediate: true });
My current solution for this is to set the immediate property to true, but this makes the component fetch the posts twice each time it's mounted, which is not ideal.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a situation where post data is fetched on initial page load in
Nuxt 3
with SSR enabled. The post endpoint displays different posts based on auth vs unauth users. This works fine in most cases except when a user goes to the page during a token refresh.During a token refresh, my app gets the new token and updates the authStore user and isAuth flag. The PostList component would watch for changes on the isAuth flag, but the problem is the watch function doesn't pick up the flag change in this case, so the Post shows the unauth version of posts.
Post Component code:
urql.config.ts code
My current solution for this is to set the immediate property to true, but this makes the component fetch the posts twice each time it's mounted, which is not ideal.
Is there a better solution to this?
Beta Was this translation helpful? Give feedback.
All reactions