import { Code } from "@/components/Code"

# Supporting corporate proxies

Auth.js libraries use the `fetch` API to communicate with OAuth providers. If your organization uses a corporate proxy, you may need to configure the `fetch` API to use the proxy.

## Using a custom fetch function

You can provide a custom `fetch` function by passing it as an option to the provider.

Here, we use the `undici` library to make requests through a proxy server, by passing a `dispatcher` to the `fetch` implementation by `undici`.

<Code>
  <Code.Next>

```tsx filename="auth.ts"
import NextAuth, { customFetch } from "next-auth"
import GitHub from "next-auth/providers/github"
import { ProxyAgent, fetch as undici } from "undici"

const dispatcher = new ProxyAgent("my.proxy.server")
function proxy(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {
  // @ts-expect-error `undici` has a `duplex` option
  return undici(args[0], { ...args[1], dispatcher })
}

export const { handlers, auth } = NextAuth({
  providers: [GitHub({ [customFetch]: proxy })],
})
```

  </Code.Next>
</Code>

## Resources

- [`undici` - Basic Proxy Request with local agent dispatcher](https://undici.nodejs.org/#/docs/api/ProxyAgent?id=example-basic-proxy-request-with-local-agent-dispatcher)
