Docs: Issue with no headers being set in setActiveOrganization docs #2449

Closed
opened 2026-03-13 09:55:28 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @JeffreyLind3 on GitHub (Dec 4, 2025).

My brain is fried so could be having a dumb moment, but auth.api.setActiveOrganization throws a linter error when I don't pass headers: await headers(). If this is intended, then the docs have an issue in https://www.better-auth.com/docs/plugins/organization#set-active-organization because it doesn't pass headers as an input to auth.api.setActiveOrganization in the example.

If headers are not actually required, then maybe linter is wrong. Below is linter output:

No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ body: { organizationSlug: string; }; }' is not assignable to parameter of type 'InputContext<"/organization/set-active", { method: "POST"; body: ZodObject<{ organizationId: ZodOptional<ZodNullable<ZodString>>; organizationSlug: ZodOptional<ZodString>; }, $strip>; use: (((inputContext: MiddlewareInputContext<...>) => Promise<...>) | ((inputContext: MiddlewareInputContext<...>) => Promise<...>))[...'.
      Property 'headers' is missing in type '{ body: { organizationSlug: string; }; }' but required in type '{ headers: HeadersInit; }'.ts(2769)
Image
Originally created by @JeffreyLind3 on GitHub (Dec 4, 2025). My brain is fried so could be having a dumb moment, but `auth.api.setActiveOrganization` throws a linter error when I don't pass `headers: await headers()`. If this is intended, then the docs have an issue in `https://www.better-auth.com/docs/plugins/organization#set-active-organization` because it doesn't pass headers as an input to `auth.api.setActiveOrganization` in the example. If headers are not actually required, then maybe linter is wrong. Below is linter output: ``` No overload matches this call. The last overload gave the following error. Argument of type '{ body: { organizationSlug: string; }; }' is not assignable to parameter of type 'InputContext<"/organization/set-active", { method: "POST"; body: ZodObject<{ organizationId: ZodOptional<ZodNullable<ZodString>>; organizationSlug: ZodOptional<ZodString>; }, $strip>; use: (((inputContext: MiddlewareInputContext<...>) => Promise<...>) | ((inputContext: MiddlewareInputContext<...>) => Promise<...>))[...'. Property 'headers' is missing in type '{ body: { organizationSlug: string; }; }' but required in type '{ headers: HeadersInit; }'.ts(2769) ``` <img width="801" height="582" alt="Image" src="https://github.com/user-attachments/assets/dd0087e0-9b7c-4246-86e1-dcf60bed0c43" />
GiteaMirror added the documentation label 2026-03-13 09:55:28 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 4, 2025):

[tag @better-auth-agent if you would like an answer from the Agent]

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Dec 4, 2025): [tag @better-auth-agent if you would like an answer from the Agent] _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 4, 2025):

The linter error is expected—auth.api.setActiveOrganization now requires a headers parameter due to recent changes in the codebase that enforce header requirements for organization-related endpoints. This is enforced by TypeScript and is not a linter bug; omitting headers will always cause a type error in current versions (source, source).

The documentation at better-auth.com is outdated and should show usage like:

await auth.api.setActiveOrganization({
  headers: await headers(),
  body: { organizationSlug: "your-org-slug" }
})

Best practice is to always pass headers: await headers() (or equivalent, depending on your environment) when calling this API. This ensures session cookies and authentication context are forwarded correctly. If you’re using Next.js or Express, use their respective request objects to construct the headers.

If you run into similar issues, check for recent updates to the docs or library—this requirement was added in late November 2025 (source).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 4, 2025): <!-- Answer --> The linter error is expected—`auth.api.setActiveOrganization` now requires a `headers` parameter due to recent changes in the codebase that enforce header requirements for organization-related endpoints. This is enforced by TypeScript and is not a linter bug; omitting `headers` will always cause a type error in current versions ([source](https://github.com/better-auth/better-auth/pull/6210), [source](https://github.com/better-auth/better-auth/blob/951dfdd7e768700d5ee3e87107b4274aefaa3aec/packages/better-auth/src/plugins/organization/routes/crud-org.ts#L752-L887)). The documentation at [better-auth.com](https://www.better-auth.com/docs/plugins/organization#set-active-organization) is outdated and should show usage like: ```ts await auth.api.setActiveOrganization({ headers: await headers(), body: { organizationSlug: "your-org-slug" } }) ``` Best practice is to always pass `headers: await headers()` (or equivalent, depending on your environment) when calling this API. This ensures session cookies and authentication context are forwarded correctly. If you’re using Next.js or Express, use their respective request objects to construct the headers. If you run into similar issues, check for recent updates to the docs or library—this requirement was added in late November 2025 ([source](https://github.com/better-auth/better-auth/pull/6210)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/41762a5c-f8ff-4c5f-86d9-3017957bc3a5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/41762a5c-f8ff-4c5f-86d9-3017957bc3a5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/41762a5c-f8ff-4c5f-86d9-3017957bc3a5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/41762a5c-f8ff-4c5f-86d9-3017957bc3a5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/41762a5c-f8ff-4c5f-86d9-3017957bc3a5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/41762a5c-f8ff-4c5f-86d9-3017957bc3a5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/41762a5c-f8ff-4c5f-86d9-3017957bc3a5?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20linter%20error%20is%20expected%E2%80%94%60auth.api.setActiveOrganization%60%20now%20requires%20a%20%60headers%60%20parameter%20due%20to%20recent%20changes%20in%20the%20codebase%20that%20enforce%20header%20requirements%20for%20organization-related%20endpoints.%20This%20is%20enforced%20by%20TypeScript%20and%20is%20not%20a%20linter%20bug%3B%20omitting%20%60headers%60%20will%20always%20cause%20a%20type%20error%20in%20current%20versions%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/pull/6210%29%2C%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/951dfdd7e768700d5ee3e87107b4274aefaa3aec/packages/better-auth/src/plugins/organization/routes/crud-org.ts%23L752-L887%29%29.%0A%0AThe%20documentation%20at%20%5Bbetter-auth.com%5D%28https%3A//www.better-auth.com/docs/plugins/organization%23set-active-organization%29%20is%20outdated%20and%20should%20show%20usage%20like%3A%0A%0A%60%60%60ts%0Aawait%20auth.api.setActiveOrganization%28%7B%0A%20%20headers%3A%20await%20headers%28%29%2C%0A%20%20body%3A%20%7B%20organizationSlug%3A%20%22your-org-slug%22%20%7D%0A%7D%29%0A%60%60%60%0A%0ABest%20practice%20is%20to%20always%20pass%20%60headers%3A%20await%20headers%28%29%60%20%28or%20equivalent%2C%20depending%20on%20your%20environment%29%20when%20calling%20this%20API.%20This%20ensures%20session%20cookies%20and%20authentication%20context%20are%20forwarded%20correctly.%20If%20you%E2%80%99re%20using%20Next.js%20or%20Express%2C%20use%20their%20respective%20request%20objects%20to%20construct%20the%20headers.%0A%0AIf%20you%20run%20into%20similar%20issues%2C%20check%20for%20recent%20updates%20to%20the%20docs%20or%20library%E2%80%94this%20requirement%20was%20added%20in%20late%20November%202025%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/pull/6210%29%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6512)
Author
Owner

@jonathansamines commented on GitHub (Dec 4, 2025):

Hey @JeffreyLind3 I think the docs are not correct, doing some amendments now.

@jonathansamines commented on GitHub (Dec 4, 2025): Hey @JeffreyLind3 I think the docs are not correct, doing some amendments now.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2449