From 5bfbe4f1d909e1ecb4e9637e222b81814155fee9 Mon Sep 17 00:00:00 2001 From: Niklas Lausch Date: Wed, 27 Dec 2023 14:12:57 +0100 Subject: [PATCH] fix: getServerToken returns null when used in middleware --- packages/authjs-nuxt/src/runtime/lib/server.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/authjs-nuxt/src/runtime/lib/server.ts b/packages/authjs-nuxt/src/runtime/lib/server.ts index effe854..85ef680 100644 --- a/packages/authjs-nuxt/src/runtime/lib/server.ts +++ b/packages/authjs-nuxt/src/runtime/lib/server.ts @@ -1,7 +1,7 @@ import type { RuntimeConfig } from "nuxt/schema" import { Auth, skipCSRFCheck } from "@auth/core" import type { H3Event } from "h3" -import { eventHandler, getRequestHeaders, getRequestURL } from "h3" +import { eventHandler, getRequestHeaders, getRequestURL, parseCookies } from "h3" import type { AuthConfig, Session } from "@auth/core/types" import { getToken } from "@auth/core/jwt" import { checkOrigin, getAuthJsSecret, getRequestFromEvent, getServerOrigin, makeCookiesFromCookieString } from "../utils" @@ -65,11 +65,11 @@ export async function getServerSession( */ export async function getServerToken(event: H3Event, options: AuthConfig, runtimeConfig?: Partial) { const response = await getServerSessionResponse(event, options) - const cookies = Object.fromEntries(response.headers.entries()) - const parsedCookies = makeCookiesFromCookieString(cookies["set-cookie"]) + const cookies = parseCookies(event) + const parameters = { req: { - cookies: parsedCookies, + cookies, headers: response.headers as unknown as Record }, // see https://github.com/nextauthjs/next-auth/blob/a79774f6e890b492ae30201f24b3f7024d0d7c9d/packages/core/src/jwt.ts