Skip to content
Discussion options

You must be logged in to vote

This usually happens due to how cookies behave between the backend and Next.js middleware, not because your code is wrong.

Common causes:

  1. Cookie not included in the request
    If your backend and frontend are on different domains or ports, the browser will NOT send cookies by default.

Fix:
Make sure your request includes credentials:

fetch("http://localhost:5000/api/...", {
credentials: "include"
});

Also enable CORS on your backend:

  • Access-Control-Allow-Credentials: true
  1. sameSite: "strict"
    You are using sameSite: "strict", which blocks cookies on cross-site requests.

Fix:
Use:
sameSite: "lax"
OR
sameSite: "none" (requires secure: true)

  1. secure: true in development
    If secure is true, c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lorenz-reelist8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development source:ui Discussions created via Community GitHub templates
2 participants