-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Cookies are being lost after redirect using middleware #7484
Comments
This was previously fixed here: #7294 It shouldn't matter which adapter it is. Possible regression? |
I would guess that the bug is specifically because of the redirect. https://github.com/i7N3/astro-middleware-bug-reproduction/blob/master/src/middleware.ts |
I tested it as described and yes, it's because of redirect. |
I think I'm facing the same thing, but I'm using the API, and it also seems to be the |
@medeirosjoaquim I was able to get it working by using import { defineMiddleware } from "astro/middleware";
// server-side rendering
export const prerender = false;
// check if user is authenticated
const handleAuthentication = defineMiddleware((context, next) => {
const astroCookies = context.cookies
const requestCookies = context.request.headers.get('cookie')
console.log("[middleware] astroCookies:", astroCookies) // {} (bad)
console.log("[middleware] requestCookies:", requestCookies) // { someCookie: 'someValue' } (good)
return next()
}) |
I found a way to redirect and prevent losing cookies
But using this approach I can't set multiple cookies at once:
|
Fixed by #8612 |
What version of
astro
are you using?2.6.1
Are you using an SSR adapter? If so, which one?
@astrojs/node: 5.2.0
What package manager are you using?
npm or pnpm
What operating system are you using?
Monterey m1
What browser are you using?
Any
Describe the Bug
I am faced with the fact that the cookie is lost after redirecting.
How to reproduce?
When I log cookie value on /dashboard page with Astro.cookies.get(...).value it's empty.
If I remove the redirect statement, then it works.
Tested both: dev and preview
What's the expected result?
Cookies should be present after redirect.
Link to Minimal Reproducible Example
https://github.com/i7N3/astro-middleware-bug-reproduction/tree/54281b3bf6e42bc5becb041c9db83aeb368d5b16
Participation
The text was updated successfully, but these errors were encountered: