Skip to content

Commit 468b057

Browse files
committed
made the GitHub API call authenticated
1 parent 5247952 commit 468b057

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

controllers/users.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ const filterUsers = async (req, res) => {
466466

467467
// one time script function to perform the migration - adding github_user_id field to the document
468468
const migrate = async (req, res) => {
469+
const authToken = `${config.get("githubOauth.clientId")}:${config.get("githubOauth.clientSecret")}`;
470+
const base64 = Buffer.from(`${authToken}`, "binary").toString("base64");
469471
try {
470472
// Fetch user data from GitHub API for each document in the users collection
471473
// divided by 500 because firestore api guarantee that we can process in batch of 500.
@@ -481,7 +483,12 @@ const migrate = async (req, res) => {
481483
batchWrite.update(userDoc.ref, { github_user_id: null });
482484
batchWrites.push(
483485
axios
484-
.get(`https://api.github.com/users/${githubUsername}`)
486+
.get(`https://api.github.com/users/${githubUsername}`, {
487+
headers: {
488+
"Content-Type": "application/json",
489+
auth: `Bearer ${base64}`,
490+
},
491+
})
485492
.then((response) => {
486493
const githubUserId = response.data.id;
487494
batchWrite.update(userDoc.ref, { github_user_id: `${githubUserId}` });

0 commit comments

Comments
 (0)