[GH-ISSUE #8802] [Docs] Use fromNodeHeaders(request.headers) in Fastify integration example #11195

Closed
opened 2026-04-13 07:32:48 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @gabrieleolmi on GitHub (Mar 27, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8802

Problem

  • The Fastify integration example in docs/content/docs/integrations/fastify.mdx manually converts Fastify/Node headers into a Fetch Headers object:
    // Convert Fastify headers to standard Headers object
    const headers = new Headers();
    Object.entries(request.headers).forEach(([key, value]) => {
      if (value) headers.append(key, value.toString());
    });
    
    This is duplicated logic and can mishandle multi-value headers and other Node-specific header edge cases.

Suggested change

  • Use the existing helper fromNodeHeaders(request.headers) from better-auth/node, which converts Node/Fastify headers into a Fetch-compatible Headers instance reliably and consistently with other examples in the docs.

Minimal replacement (suggested diff):

-      const headers = new Headers();
-      Object.entries(request.headers).forEach(([key, value]) => {
-        if (value) headers.append(key, value.toString());
-      });
+      import { fromNodeHeaders } from "better-auth/node";
+      const headers = fromNodeHeaders(request.headers);
Originally created by @gabrieleolmi on GitHub (Mar 27, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8802 Problem - The Fastify integration example in [docs/content/docs/integrations/fastify.mdx](https://github.com/better-auth/better-auth/blob/main/docs/content/docs/integrations/fastify.mdx) manually converts Fastify/Node headers into a Fetch Headers object: ```ts // Convert Fastify headers to standard Headers object const headers = new Headers(); Object.entries(request.headers).forEach(([key, value]) => { if (value) headers.append(key, value.toString()); }); ``` This is duplicated logic and can mishandle multi-value headers and other Node-specific header edge cases. Suggested change - Use the existing helper `fromNodeHeaders(request.headers)` from `better-auth/node`, which converts Node/Fastify headers into a Fetch-compatible Headers instance reliably and consistently with other examples in the docs. Minimal replacement (suggested diff): ```diff - const headers = new Headers(); - Object.entries(request.headers).forEach(([key, value]) => { - if (value) headers.append(key, value.toString()); - }); + import { fromNodeHeaders } from "better-auth/node"; + const headers = fromNodeHeaders(request.headers); ```
GiteaMirror added the platformjavascriptlocked labels 2026-04-13 07:32:48 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Apr 4, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4185770473 --> @github-actions[bot] commented on GitHub (Apr 4, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11195