-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fetch GitHub repositories of an authenticated principal
- Loading branch information
이은상
committed
Dec 27, 2024
1 parent
14d3efd
commit 8459c91
Showing
6 changed files
with
82 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Request, Response } from "express"; | ||
import { authenticate } from "../decorators/AuthDecorator"; | ||
import axios from "axios"; | ||
|
||
const GITHUB_API_URL = "https://api.github.com"; | ||
|
||
export class GitHubController { | ||
@authenticate() | ||
async getRepositories(req: Request, res: Response) { | ||
try { | ||
const user = req.user; | ||
|
||
// Get user info from GitHub using the access token | ||
const repoResponse = await axios.get(`${GITHUB_API_URL}/users/${user?.username}/repos`, { | ||
headers: { Authorization: `Bearer ${user?.ghAccessToken}` }, | ||
}); | ||
|
||
if (user) { | ||
res.send({ | ||
username: user.username, | ||
repositories: repoResponse.data | ||
}); | ||
} | ||
} catch (error) { | ||
console.error("Error in getUsername:", error); | ||
res.status(500).send({ error: "Internal Server Error" }); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
7_auth/7_1_express_js/src/controllers/ProtectedController.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters