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

setCookie not working in _middleware #507

Closed
Amber-Williams opened this issue Nov 5, 2021 · 1 comment
Closed

setCookie not working in _middleware #507

Amber-Williams opened this issue Nov 5, 2021 · 1 comment
Labels

Comments

@Amber-Williams
Copy link

setCookie seems to work fine when used in a Nextjs api route, but in Next's latest released _middleware file doesn't work.

This can be reproduced my creating a _middleware.ts file with the following

import type { NextRequest } from "next/server"
import { NextResponse } from "next/server"
import { setCookie } from "nookies"

const AuthMiddleware = async (req: NextRequest) => {
  let res = NextResponse.next()
  setCookie({ res }, "test", "test value", {
    path: "/",
  })

  return res
}

However using the NextResponse res.cookie("test", "test value") works. Unfortunately that method it doesn't play well with Typescript for options

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
@stale stale bot closed this as completed Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant