Skip to content

fix: align parseCookieHeader return type with getAll cookie method#239

Open
TheSeydiCharyyev wants to merge 1 commit into
supabase:mainfrom
TheSeydiCharyyev:fix/issue-115-cookie-header-type
Open

fix: align parseCookieHeader return type with getAll cookie method#239
TheSeydiCharyyev wants to merge 1 commit into
supabase:mainfrom
TheSeydiCharyyev:fix/issue-115-cookie-header-type

Conversation

@TheSeydiCharyyev
Copy link
Copy Markdown

Description

parseCookieHeader returns { name: string; value?: string }[], but the getAll cookie method (GetAllCookies in CookieMethodsServer) requires { name: string; value: string }[]. As a result, the documented server pattern fails to type-check:

getAll() {
  return parseCookieHeader(request.headers.get("cookie") ?? "");
  // Type '{ name: string; value?: string }[]' is not assignable to
  // '{ name: string; value: string }[]'.
}

Fix

Normalize the value with ?? "" and drop the optional from the return type, so parseCookieHeader is directly assignable to getAll. This mirrors the library's own documentCookieGetAll, which already uses parsed[name] ?? "".

For a key returned by Object.keys(parsed) the value is always a string at runtime, so this is a no-op for normal cookies and normalizes a valueless cookie (a=) to "" — consistent with documentCookieGetAll. Narrowing the return type from string | undefined to string is not a breaking change for consumers reading the value.

Testing

  • Added a regression test in helpers.spec.ts that asserts the returned values are strings and that parseCookieHeader satisfies the GetAllCookies contract at compile time (const getAll: GetAllCookies = () => parseCookieHeader("a=b")), so a future regression fails tsc.
  • pnpm build (tsc), pnpm test (87 passed), pnpm exec prettier --check, pnpm exec eslint — all pass. Existing snapshots unchanged.

Fixes #115

parseCookieHeader returned an optional value type, which is incompatible with the getAll cookie method (GetAllCookies) that requires a string. This broke the documented server pattern getAll() { return parseCookieHeader(...) }. Normalize the value to a string, mirroring the library's own documentCookieGetAll.

Fixes supabase#115
@TheSeydiCharyyev TheSeydiCharyyev requested review from a team as code owners June 1, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The parameter types of parseCookieHeader and createServerClient are incompatible

1 participant