Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use custom fetch if defined in GitHub userInfo #12668

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/core/src/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

import type { OAuthConfig, OAuthUserConfig } from "./index.js"
import { customFetch } from "../lib/index.js"

export interface GitHubEmail {
email: string
Expand Down Expand Up @@ -134,6 +135,7 @@ export default function GitHub(
const apiBaseUrl = config?.enterprise?.baseUrl
? `${config?.enterprise?.baseUrl}/api/v3`
: "https://api.github.com"
const fetchToUse = config[customFetch] ?? fetch;

return {
id: "github",
Expand All @@ -147,7 +149,7 @@ export default function GitHub(
userinfo: {
url: `${apiBaseUrl}/user`,
async request({ tokens, provider }) {
const profile = await fetch(provider.userinfo?.url as URL, {
const profile = await fetchToUse(provider.userinfo?.url as URL, {
headers: {
Authorization: `Bearer ${tokens.access_token}`,
"User-Agent": "authjs",
Expand All @@ -157,7 +159,7 @@ export default function GitHub(
if (!profile.email) {
// If the user does not have a public email, get another via the GitHub API
// See https://docs.github.com/en/rest/users/emails#list-public-email-addresses-for-the-authenticated-user
const res = await fetch(`${apiBaseUrl}/user/emails`, {
const res = await fetchToUse(`${apiBaseUrl}/user/emails`, {
headers: {
Authorization: `Bearer ${tokens.access_token}`,
"User-Agent": "authjs",
Expand Down