bvttercvp
bvttercvp
NNuxt
Created by bvttercvp on 4/14/2025 in #❓・help
Data fetching on SSR using useFetch/useAsyncData does not work on page refresh/reload
No description
7 replies
NNuxt
Created by bvttercvp on 4/10/2025 in #❓・help
useRequestFetch does not pass cookie when path is not "/" on ssr
I have a refresh token API in the backend. The refresh token is saved to cookie storage during login with path specific to the refresh token API (e.g. path=/api/refresh-token). However, whenever I try to call this API during SSR in frontend and debug with the backend refresh token API, refresh token value from cookie is always empty. This is how I make a request with useRequestFetch.
const requestFetch = useRequestFetch()
const postResponse = async (
endpoint: string,
body?: object,
) => {
const response = await requestFetch(endpoint, {
baseURL: config.public.domain,
method: HTTP_METHOD_POST,
body,
})
return response
}

const { data, error } = await useAsyncData(async () => await postResponse('/api/refresh-token'))
const requestFetch = useRequestFetch()
const postResponse = async (
endpoint: string,
body?: object,
) => {
const response = await requestFetch(endpoint, {
baseURL: config.public.domain,
method: HTTP_METHOD_POST,
body,
})
return response
}

const { data, error } = await useAsyncData(async () => await postResponse('/api/refresh-token'))
NOTE: * I have also tried to useFetch but similar issue occurs. * Client-side fetch passes cookie as expected using the above postResponse method.
11 replies