Skip to content

Commit

Permalink
fix: use custom fetch if defined in GitHub userInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-lepikhin committed Feb 18, 2025
1 parent ec57440 commit 394956a
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit 394956a

Please sign in to comment.