diff --git a/server/jobs/fetch-user-profile.ts b/server/jobs/fetch-user-profile.ts index b5efda6..a9f4c88 100644 --- a/server/jobs/fetch-user-profile.ts +++ b/server/jobs/fetch-user-profile.ts @@ -13,7 +13,13 @@ export const fetchUserProfile = async (data: FetchUserProfileType) => { if (!user) { throw new Error("User not found!"); } - const details = await github.getUser(user.username); + + const accessToken = user.accessToken || import.meta.env.GITHUB_DEFAULT_TOKEN; + const details = await github.getUser(user.username, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); await db .update(users) diff --git a/server/lib/github.ts b/server/lib/github.ts index 48f187d..e921e84 100644 --- a/server/lib/github.ts +++ b/server/lib/github.ts @@ -26,8 +26,8 @@ const selectors = { }; const github = { - async getUser(username: string) { - const response = await this.fetch(username); + async getUser(username: string, options?: Partial) { + const response = await this.fetch(username, options); const $ = cheerio.load(response); const name = $(selectors.user.name).text().trim(); @@ -43,13 +43,21 @@ const github = { achievements.push({ name, image }); }); + const user = await github.fetch(`users/${username}`, { + ghApi: true, + headers: { + accept: "application/json", + ...(options?.headers || {}), + }, + }); + return { name: name || username, avatar, username, location, - followers, - following, + followers: user.followers || followers, + following: user.following || following, achievements, }; },