Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Response cookies missing in middleware | GoodFirstPicks

Response cookies missing in middleware

vercel/next.js 4 comments 1mo ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeNext.jsTypeScriptReact

Why this is a good first issue

Middleware cannot access cookies set in server actions.

AI Summary

The issue involves cookies set in server actions not being accessible in middleware responses. The problem is reproducible but requires understanding of both server actions and middleware cookie handling. The scope is somewhat clear but involves cross-cutting concerns between different Next.js features.

Issue Description

Link to the code that reproduces this issue

https://github.com/marcospassos/next-middleware-cookie-bug

To Reproduce

If you set a cookie in a server action, it is not available in the middleware. Without this, the middleware cannot prevent overriding cookies that may be set at the request time.

To Reproduce

Create a server action:

'use server';

import {cookies} from 'next/headers';

export async function example(): Promise<void> {
    cookies().set('foo', 'bar');
}

Then, in your middleware:

export function middleware(): void {
    const response = NextResponse.next();
    
    console.log(response.cookies.has('foo'));   
}

The result is always false.

Current vs. Expected behavior

The response should include the cookies set in server actions.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 11
Binaries:
  Node: 21.7.3
  npm: 10.5.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.0.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Middleware

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

GitHub Labels

bugMiddleware

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!

Risk Flags

  • cookie handling
  • middleware-server action interaction
Loading labels...

Details

Points20 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno