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

fix: getServerToken returns null when used in middleware #147

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/authjs-nuxt/src/runtime/lib/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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"
import { checkOrigin, getAuthJsSecret, getRequestFromEvent, getServerOrigin } from "../utils"

if (!globalThis.crypto) {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -65,11 +65,11 @@ export async function getServerSession(
*/
export async function getServerToken(event: H3Event, options: AuthConfig, runtimeConfig?: Partial<RuntimeConfig>) {
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<string, string>
},
// see https://github.com/nextauthjs/next-auth/blob/a79774f6e890b492ae30201f24b3f7024d0d7c9d/packages/core/src/jwt.ts
Expand Down