Skip to content

le-u-f/astro-cookies-middleware-issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

If you use an Astro.cookies.set(...) and a middleware that rewrites the response (as in your documentation), the cookies are not forwarded.

// src/middleware.js

export const onRequest = async (context, next) => {
    const response = await next();
    const html = await response.text();

    return new Response(html, {
        status: 200,
        headers: response.headers
    });
};

This does not work :

// src/pages/foo.astro

Astro.cookies.set("astro", "cookie", {
    httpOnly: true,
    path: "/",
    sameSite: "strict",
    maxAge: 1704085200,
  });

But this works :

// src/pages/foo.astro

Astro.response.headers.set(
    "Set-Cookie",
    "common=cookie; Path=/; HttpOnly; SameSite=Strict; Max-Age=1704085200",
  );

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published