Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set cookies on Astro routes #37

Open
PeterDraex opened this issue Jun 16, 2024 · 0 comments
Open

Can't set cookies on Astro routes #37

PeterDraex opened this issue Jun 16, 2024 · 0 comments

Comments

@PeterDraex
Copy link

I set up a Fastify middleware like to create a cookie. The cookie is created correctly for Fastify routes (/api/todos), but the cookies don't make it to the HTTP response of Astro pages.

My index.ts:

import fastifyCookie from '@fastify/cookie';
import type { DefineFastifyRoutes } from '@matthewp/astro-fastify';

const defineRoutes: DefineFastifyRoutes = (fastify) => {
    fastify.register(fastifyCookie);

    fastify.addHook("onRequest", async (request, reply) => {
      reply.setCookie("someCookie", "someValue");
    });

    fastify.get('/api/todos', function(request, reply) {
    reply.send({
      todos: [
        { label: 'eat lunch' },
        { label: 'exercise' },
        { label: 'walk the dog' }
      ]
    });
});

I've tried adding a console.log to the middleware and it gets printed for both pages, so it seems like reply.setCookie is executed in both cases. Why is the cookie missing from Astro routes HTTP response (I've checked via Chrome Developer Tools)? It seems like a bug? Is there a workaround?

Thanks!

@PeterDraex PeterDraex changed the title Can't set cookie on Astro routes Can't set cookies on Astro routes Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant