#Astro action to logout/destory cookies doesn't work on vercel

12 messages · Page 1 of 1 (latest)

barren oar
#

Is there anything wrong with this? Works find on local host.

  logoutUser: defineAction({
    handler: (_, context) => {
      const TOKEN = import.meta.env.TOKEN

      try {
        context.cookies.set(TOKEN, '', {
          httpOnly: true,
          maxAge: 0,
          path: '/',
          secure: true,
          sameSite: 'lax',
        })

        return true
      } catch (error) {
        console.error('Error logging out: ', error)
        throw new Error(error.message || error)
      }
    },
  }),

When deployed to vercel I get:

17:03:11 [ERROR] SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at parseJSONFromBytes (node:internal/deps/undici/undici:5584:19) at successSteps (node:internal/deps/undici/undici:5555:27) at fullyReadBody (node:internal/deps/undici/undici:1665:9) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async specConsumeBody (node:internal/deps/undici/undici:5564:7) at async Module.POST (file:///var/task/vercel/path0/.vercel/output/_functions/chunks/route_Yu3iUWSv.mjs:17:12) at async renderEndpoint (file:///var/task/vercel/path0/.vercel/output/_functions/chunks/astro/server_CBvJsTK-.mjs:45:20) at async lastNext (file:///var/task/vercel/path0/.vercel/output/_functions/entry.mjs:1031:23) at async callMiddleware (file:///var/task/vercel/path0/.vercel/output/_functions/entry.mjs:480:10)
#

guess I can just delete the cookie inside a <sceript>

barren oar
#

If anyone else has this problem it's fixed by changing
const { data, error } = await actions.logoutUser.safe()
to
const { data, error } = await actions.logoutUser.safe({})

tawdry lava
#

I thought this was fixed, are you on astro latest?

barren oar
#

Maybe you have to pass safe() an empty object if it doesn't have any arguments?

#

And it worked fine as const { data, error } = await actions.logoutUser.safe() on local host. I even tried using the node adapter (instead of the vercel adapter) and it worked fine with node adapter when I ran npm run build and ran entry.mjs

#

So I think i's a vercel issue

tawdry lava
#

Can you open an issue? That would help us a lot

thorn groveBOT
barren oar
#

Yes sir