Skip to content

Commit ca30e90

Browse files
authored
docs: update corporate-proxy.mdx with https-proxy-agent example (#12817)
Update corporate-proxy.mdx Added HttpsProxyAgent support to corporate proxies. Undici library fails behind certain firewalls and on edge runtime.
1 parent 8f9f455 commit ca30e90

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/pages/guides/corporate-proxy.mdx

+31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Auth.js libraries use the `fetch` API to communicate with OAuth providers. If yo
88

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

11+
# Using Undici Library
12+
1113
Here, we use the `undici` library to make requests through a proxy server, by passing a `dispatcher` to the `fetch` implementation by `undici`.
1214

1315
<Code>
@@ -32,6 +34,35 @@ export const { handlers, auth } = NextAuth({
3234
</Code.Next>
3335
</Code>
3436

37+
# Using HttpsProxyAgent
38+
39+
On Edge Runtimes or with proxy restrictions, the `undici` library may not work. Using a simpler approach with HttpsProxyAgent by passing a `proxyAgent` to the `fetch` implementation.
40+
41+
<Code>
42+
<Code.Next>
43+
44+
```tsx filename="auth.ts"
45+
import NextAuth, { customFetch } from "next-auth"
46+
import GitHub from "next-auth/providers/github"
47+
const { HttpsProxyAgent } = require('https-proxy-agent');
48+
49+
const proxyAgent = new HttpsProxyAgent("my.proxy.server");
50+
async function proxy(url: string, options: any): Promise<Response> {
51+
const response = (await fetch(url, {
52+
...options,
53+
agent: proxyAgent,
54+
})) as unknown as Response;
55+
return response;
56+
}
57+
58+
export const { handlers, auth } = NextAuth({
59+
providers: [GitHub({ [customFetch]: proxy })],
60+
})
61+
```
62+
63+
</Code.Next>
64+
</Code>
65+
3566
## Resources
3667

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

0 commit comments

Comments
 (0)