react-login-github
v2.0.0
Published
A React Component for GitHub Login
Maintainers
Readme
This is a fork of react-github-login since the project seems to be abandoned. This fork includes:
- Supports React 16 through 19.
- Popup custom position.
- Popup auto-center by default.
- Disable button property.
React Login with Github
React component for GitHub Login.
Usage
Install it from npm:
yarn add react-login-githubor using npm:
npm install react-login-github --saveThen use it in your app:
import React from 'react';
import { createRoot } from 'react-dom/client';
import LoginGithub from 'react-login-github';
const onSuccess = response => console.log(response);
const onFailure = response => console.error(response);
createRoot(document.getElementById('example')).render(
<LoginGithub clientId="ac56fad434a3a3c1561e"
onSuccess={onSuccess}
onFailure={onFailure}
/>
);Props
clientId
{string} required
Client ID for GitHub OAuth application.
redirectUri
{string}
Registered redirect URI for GitHub OAuth application.
scope
{string}
Scope for GitHub OAuth application. Defaults to user:email.
className
{string}
CSS class for the login button.
buttonText
{string}
Text content for the login button.
onRequest
{function}
Callback for every request.
onSuccess
{function}
Callback for successful login. An object will be passed as an argument to the callback, e.g. { "code": "..." }.
onFailure
{function}
Callback for errors raised during login.
disabled
{bool}
Disable login button.
Development
$ npm install
$ npm run build # bundle src/ into dist/ (cjs + esm) with tsup
$ npm test # run the Jest + Testing Library suite
$ npm run lint # run ESLintRunning the example app
A small demo app lives in example/ and imports the component straight from src/, so changes to the library are reflected immediately.
Start the dev server:
$ npm startOpen http://localhost:3000 in your browser.
Create a GitHub OAuth App with its authorization callback URL set to
http://localhost:3000.Paste the app's Client ID into the demo page's "Client ID" field and click "Sign in with GitHub" to try the full login flow.
