UNPKG

react-floating-profile

Version:

React component to display your github profile <p align="left"> <a href="https://www.npmjs.com/package/react-floating-profile"><img src="https://flat.badgen.net/npm/v/react-floating-profile" alt="react-floating-profile version" /></a> <a href="http

23 lines (19 loc) 729 B
import { GitHubUser } from "../types"; export default async function getUserProfile(username: string, accessToken: string): Promise<GitHubUser> { // const url = "https://api.github.com/user"; const url = `https://api.github.com/users/${username}`; const response = await fetch(url, { method: "GET", headers: { ...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}), Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", "Content-Type": "application/json", }, }); if (!response.ok) { const errorData = await response.json(); throw new Error(`GitHub API Error: ${errorData.message}`); } return response.json(); }