Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sametcn99 committed Aug 3, 2024
1 parent 7bea17d commit 4892ca6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/api/star-history/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { auth } from "@clerk/nextjs/server";
import { NextRequest, NextResponse } from "next/server";
import createOctokitInstance from "../../../lib/createOctokitInstance";
import { auth } from "@clerk/nextjs/server";

/**
* Fetches stargazers for a GitHub repo from the GitHub API.
Expand All @@ -11,7 +11,8 @@ import { auth } from "@clerk/nextjs/server";
* @returns A promise resolving to the array of stargazer records for the requested page
*/
async function fetchStargazers(username: string, repo: string, page: number) {
const octokit = await createOctokitInstance();
const { userId } = auth();
const octokit = await createOctokitInstance(userId ? userId : undefined);
const responseData = await octokit.rest.activity.listStargazersForRepo({
owner: username,
repo: repo,
Expand Down
11 changes: 10 additions & 1 deletion lib/createOctokitInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import { clerkClient } from "@clerk/nextjs/server";
import { Octokit } from "octokit";

export default async function createOctokitInstance(userId?: string) {
// set token in development mode
let auth;
if (userId !== null && userId !== undefined) {

if (process.env.NODE_ENV === "development")
auth = process.env.GITHUB_TOKEN || "";

if (
userId !== null &&
userId !== undefined &&
process.env.NODE_ENV !== "development"
) {
const user = await clerkClient.users.getUser(userId);
auth = user.unsafeMetadata.token as string;
}
Expand Down

1 comment on commit 4892ca6

@vercel
Copy link

@vercel vercel bot commented on 4892ca6 Aug 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.