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

await session.save() fails to set cookie if cookies.set() is used after #684

Open
Emrin opened this issue Jan 6, 2024 · 2 comments
Open

Comments

@Emrin
Copy link

Emrin commented Jan 6, 2024

I tested this in middleware and any invocation of response.cookies.set() on a NextResponse after saving the session with await session.save() will not set the new session as a cookie.

@calebjoshuapaul
Copy link

Same here, cookie won't update on session.save() if another cookie has been set using document.setCookie()

@romeobravo
Copy link

romeobravo commented Mar 18, 2024

I can confirm this issue. We are chaining middleware functions together.

Simplified examples:

function setCookieMiddleware(req, res, ctx) {
  res.cookies.set('foo', 'bar', { httpOnly: false })
  return res
}

async function saveSessionMiddleware(req, res, ctx) {
  ctx.session.foo = 'bar'
  await ctx.session.save()

  return response
}


// DOES NOT WORK: session cookie is not set in response headers, only foo cookie is present
const middlewares = [
  saveSessionMiddleware,
  setCookieMiddleware,
]

// DOES WORK: both session cookie and foo cookie Set Cookie header present in response headers
const middlewares = [
  setCookieMiddleware,
  saveSessionMiddleware,
]

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

3 participants