Skip to content

Commit

Permalink
Include cookie headers on session fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
silverbackdan committed Dec 23, 2024
1 parent 8d31537 commit 2afe6f3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { type UseAuthStateReturn, useAuthState } from './useAuthState'
import { callWithNuxt } from '#app/nuxt'
// @ts-expect-error - #auth not defined
import type { SessionData } from '#auth'
import { navigateTo, nextTick, useNuxtApp, useRoute, useRuntimeConfig } from '#imports'
import { navigateTo, nextTick, useNuxtApp, useRequestHeaders, useRoute, useRuntimeConfig } from '#imports'

type Credentials = { username?: string, email?: string, password?: string } & Record<string, any>

Expand Down Expand Up @@ -130,7 +130,10 @@ async function getSession(getSessionOptions?: GetSessionOptions): Promise<Sessio
return
}

const headers = new Headers(token ? { [config.token.headerName]: token } as HeadersInit : undefined)
const headers = new Headers(useRequestHeaders(['cookie']))
if (token) {
headers.append(config.token.headerName, token)
}

loading.value = true
try {
Expand Down

0 comments on commit 2afe6f3

Please sign in to comment.