setCookie() in Nuxt3 server

32 views Asked by At

This is the code in /server/api of my Nuxt3 project.

// server/api/getevents.ts
export default defineEventHandler(async (req) => {
    setCookie(req, 'Token', "token here...")
    const response = await $fetch("localhost:3001/events", {method: 'post'})
    return response
})

The issue I am facing is that setCookie() doesn't work cuz of return response code block in the code above. If I don't write return response, setCookie() works well. But I need to return the response to the client. I guess this is related to the SSR but cannot find the solution yet. please help me.

I tried to remove return response code. Then it worked. But I need that code and if I use it setCookie() doesn't work.

0

There are 0 answers