Skip to content

Commit

Permalink
fix(edge): support request.cookies as a map (#4745)
Browse files Browse the repository at this point in the history
in next Next.js versions, NextRequest.cookies will be an instance of NextCookies which is
some kind of a Map, instead of a plain object.

This commit checks whether there's a `get` function in req.cookies, and acts accordingly,
to make sure we will support newer Next.js versions with Edge Functions/Middleware
  • Loading branch information
Schniz committed Jun 21, 2022
1 parent e498483 commit 73d489b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/next-auth/src/core/lib/cookie.ts
Expand Up @@ -120,7 +120,7 @@ export class SessionStore {
constructor(
option: CookieOption,
req: {
cookies?: Record<string, string>
cookies?: Record<string, string> | { get: (key: string) => string }
headers?: Headers | IncomingHttpHeaders | Record<string, string>
},
logger: LoggerInstance | Console
Expand All @@ -132,7 +132,10 @@ export class SessionStore {

for (const name in req.cookies) {
if (name.startsWith(option.name)) {
this.#chunks[name] = req.cookies[name]
this.#chunks[name] =
typeof req.cookies.get === "function"
? req.cookies.get(name)
: req.cookies[name]
}
}
}
Expand Down

0 comments on commit 73d489b

Please sign in to comment.