Skip to content

Commit

Permalink
Use new ResponseCookie API
Browse files Browse the repository at this point in the history
  • Loading branch information
HaNdTriX committed Nov 2, 2022
1 parent c4087fc commit 04ea576
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/next-auth/src/core/lib/cookie.ts
@@ -1,6 +1,7 @@
import type { IncomingHttpHeaders } from "http"
import type { CookiesOptions } from "../.."
import type { CookieOption, LoggerInstance, SessionStrategy } from "../types"
import type { NextRequest } from "next/server"
import type { NextApiRequest } from "next"

// Uncomment to recalculate the estimated size
// of an empty session cookie
Expand Down Expand Up @@ -128,10 +129,10 @@ export class SessionStore {

constructor(
option: CookieOption,
req: {
cookies?: Partial<Record<string, string> | Map<string, string>>
headers?: Headers | IncomingHttpHeaders | Record<string, string>
},
req: Partial<{
cookies: NextRequest["cookies"] | NextApiRequest["cookies"]
headers: NextRequest["headers"] | NextApiRequest["headers"]
}>,
logger: LoggerInstance | Console
) {
this.#logger = logger
Expand All @@ -140,7 +141,14 @@ export class SessionStore {
const { cookies } = req
const { name: cookieName } = option

if (cookies instanceof Map) {
if (typeof cookies?.getAll === "function") {
// Next.js ^v13.0.1 (Edge Env)
for (const { name, value } of cookies.getAll()) {
if (name.startsWith(cookieName)) {
this.#chunks[name] = value
}
}
} else if (cookies instanceof Map) {
for (const name of cookies.keys()) {
if (name.startsWith(cookieName)) this.#chunks[name] = cookies.get(name)
}
Expand Down

0 comments on commit 04ea576

Please sign in to comment.