[GH-ISSUE #7396] [Feature Request] Allow fetchOptions to be passed in options for betterAuth (not client). #28125

Closed
opened 2026-04-17 19:31:52 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @stayclaxxy on GitHub (Jan 15, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7396

Is this suited for github?

  • Yes, this is suited for github

Currently, the createAuthClient options allow for fetchOptions. This would be nice to also have on the server-side so we can write custom fetch implementations when needed. For example, my company uses a corporate proxy. In Next-Auth there was a work around to allow the openid client to make requests through the proxy. There is no current work around or support for this in better-auth.

https://next-auth.js.org/tutorials/corporate-proxy
https://authjs.dev/guides/corporate-proxy

Describe the solution you'd like

It would be nice to allow the fetch options to be passed through the configuration so that all outbound requests to the provider are used. Please support all built-in social providers, as well as the generic oAuthProvider plugin as well.

Describe alternatives you've considered

None as of yet.

Additional context

No response

Originally created by @stayclaxxy on GitHub (Jan 15, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7396 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently, the `createAuthClient` options allow for `fetchOptions`. This would be nice to also have on the server-side so we can write custom fetch implementations when needed. For example, my company uses a corporate proxy. In Next-Auth there was a work around to allow the openid client to make requests through the proxy. There is no current work around or support for this in better-auth. https://next-auth.js.org/tutorials/corporate-proxy https://authjs.dev/guides/corporate-proxy ### Describe the solution you'd like It would be nice to allow the fetch options to be passed through the configuration so that all outbound requests to the provider are used. Please support all built-in social providers, as well as the generic oAuthProvider plugin as well. ### Describe alternatives you've considered None as of yet. ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-17 19:31:52 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 15, 2026):

It seems like you're looking for a feature in Better Auth that allows fetchOptions to be passed for server-side initialization. Currently, Better Auth supports passing fetchOptions when creating the auth client with the createAuthClient method. This includes the ability to handle rate limit errors and customize fetch options for client actions [2][3].

For server-side, this capability does not seem to be explicitly supported at the moment based on the available documentation. However, there may be existing discussions or feature requests regarding this issue. You might want to create or keep an eye on an open issue for this feature, as it could help facilitate fetching through custom implementations like a corporate proxy [4].

If you would like an official response or further assistance, please tag the Better Auth team members, Beka and Max, with @bekacru and @ping__.

Is there a specific use case you're trying to solve with your authentication setup?

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

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3756055060 --> @better-auth-agent[bot] commented on GitHub (Jan 15, 2026): It seems like you're looking for a feature in Better Auth that allows `fetchOptions` to be passed for server-side initialization. Currently, Better Auth supports passing `fetchOptions` when creating the auth client with the `createAuthClient` method. This includes the ability to handle rate limit errors and customize fetch options for client actions [[2]](https://www.better-auth.com/docs/concepts/rate-limit)[[3]](https://www.better-auth.com/docs/concepts/client). For server-side, this capability does not seem to be explicitly supported at the moment based on the available documentation. However, there may be existing discussions or feature requests regarding this issue. You might want to create or keep an eye on an open issue for this feature, as it could help facilitate fetching through custom implementations like a corporate proxy [[4]](https://github.com/better-auth/better-auth/pull/6661). If you would like an official response or further assistance, please tag the Better Auth team members, Beka and Max, with @bekacru and @ping__. Is there a specific use case you're trying to solve with your authentication setup? _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/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@himself65 commented on GitHub (Jan 15, 2026):

Install undici and configure the proxy

import { betterAuth } from "better-auth";
import { ProxyAgent, setGlobalDispatcher } from "undici";

const proxyAgent = new ProxyAgent("http://your-proxy.example.com:8080");
setGlobalDispatcher(proxyAgent);

export const auth = betterAuth({
  // your configuration
});

I don't think it should be from our side, since you are running code on the server side. You have fully control of the side-effect(undici.fetch)

Refs: https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md

<!-- gh-comment-id:3756282113 --> @himself65 commented on GitHub (Jan 15, 2026): Install undici and configure the proxy ```typescript import { betterAuth } from "better-auth"; import { ProxyAgent, setGlobalDispatcher } from "undici"; const proxyAgent = new ProxyAgent("http://your-proxy.example.com:8080"); setGlobalDispatcher(proxyAgent); export const auth = betterAuth({ // your configuration }); ``` I don't think it should be from our side, since you are running code on the server side. You have fully control of the side-effect(undici.fetch) Refs: https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md
Author
Owner

@stayclaxxy commented on GitHub (Jan 15, 2026):

Install undici and configure the proxy

import { betterAuth } from "better-auth";
import { ProxyAgent, setGlobalDispatcher } from "undici";

const proxyAgent = new ProxyAgent("http://your-proxy.example.com:8080");
setGlobalDispatcher(proxyAgent);

export const auth = betterAuth({
// your configuration
});

I don't think it should be from our side, since you are running code on the server side. You have fully control of the side-effect(undici.fetch)

Refs: https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md

I swore I tried this yesterday, let me double check and give it another shot. Thanks for the suggestion.

<!-- gh-comment-id:3756286370 --> @stayclaxxy commented on GitHub (Jan 15, 2026): > Install undici and configure the proxy > > import { betterAuth } from "better-auth"; > import { ProxyAgent, setGlobalDispatcher } from "undici"; > > const proxyAgent = new ProxyAgent("http://your-proxy.example.com:8080"); > setGlobalDispatcher(proxyAgent); > > export const auth = betterAuth({ > // your configuration > }); > > I don't think it should be from our side, since you are running code on the server side. You have fully control of the side-effect(undici.fetch) > > Refs: https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md I swore I tried this yesterday, let me double check and give it another shot. Thanks for the suggestion.
Author
Owner

@himself65 commented on GitHub (Jan 15, 2026):

Install undici and configure the proxy
import { betterAuth } from "better-auth";
import { ProxyAgent, setGlobalDispatcher } from "undici";
const proxyAgent = new ProxyAgent("http://your-proxy.example.com:8080");
setGlobalDispatcher(proxyAgent);
export const auth = betterAuth({
// your configuration
});
I don't think it should be from our side, since you are running code on the server side. You have fully control of the side-effect(undici.fetch)
Refs: https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md

I swore I tried this yesterday, let me double check and give it another shot. Thanks for the suggestion.

Please ping me if you find anything wrong

<!-- gh-comment-id:3756333353 --> @himself65 commented on GitHub (Jan 15, 2026): > > Install undici and configure the proxy > > import { betterAuth } from "better-auth"; > > import { ProxyAgent, setGlobalDispatcher } from "undici"; > > const proxyAgent = new ProxyAgent("http://your-proxy.example.com:8080"); > > setGlobalDispatcher(proxyAgent); > > export const auth = betterAuth({ > > // your configuration > > }); > > I don't think it should be from our side, since you are running code on the server side. You have fully control of the side-effect(undici.fetch) > > Refs: https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md > > I swore I tried this yesterday, let me double check and give it another shot. Thanks for the suggestion. Please ping me if you find anything wrong
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#28125