Skip to content

Commit 73d489b

Browse files
authoredJun 21, 2022
fix(edge): support request.cookies as a map (#4745)
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
1 parent e498483 commit 73d489b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎packages/next-auth/src/core/lib/cookie.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class SessionStore {
120120
constructor(
121121
option: CookieOption,
122122
req: {
123-
cookies?: Record<string, string>
123+
cookies?: Record<string, string> | { get: (key: string) => string }
124124
headers?: Headers | IncomingHttpHeaders | Record<string, string>
125125
},
126126
logger: LoggerInstance | Console
@@ -132,7 +132,10 @@ export class SessionStore {
132132

133133
for (const name in req.cookies) {
134134
if (name.startsWith(option.name)) {
135-
this.#chunks[name] = req.cookies[name]
135+
this.#chunks[name] =
136+
typeof req.cookies.get === "function"
137+
? req.cookies.get(name)
138+
: req.cookies[name]
136139
}
137140
}
138141
}

0 commit comments

Comments
 (0)
Please sign in to comment.