Skip to content

Commit

Permalink
Merge pull request #172 from manchenkoff/session-cookie-preserve
Browse files Browse the repository at this point in the history
fix: keep same session on SSR requests
  • Loading branch information
manchenkoff authored Sep 25, 2024
2 parents 71473ab + fc96f34 commit 7d426fb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/runtime/interceptors/cookie/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Headers = HeadersInit | undefined

const SECURE_METHODS = new Set(['post', 'delete', 'put', 'patch'])
const COOKIE_OPTIONS: { readonly: true } = { readonly: true }
const CLIENT_HEADERS = ['cookie', 'user-agent']

/**
* Pass all cookies, headers and referrer from the client to the API
Expand All @@ -24,14 +25,14 @@ function buildServerHeaders(
headers: Headers,
config: ModuleOptions,
): HeadersInit {
const clientCookies = useRequestHeaders(['cookie'])
const clientHeaders = useRequestHeaders(CLIENT_HEADERS)
const origin = config.origin ?? useRequestURL().origin

return {
...headers,
Referer: origin,
Origin: origin,
...(clientCookies.cookie && clientCookies),
...clientHeaders,
}
}

Expand Down

0 comments on commit 7d426fb

Please sign in to comment.