From 3ea913e8c6a227f5db6c163f0bc2439eb78d66eb Mon Sep 17 00:00:00 2001 From: manishsaraan Date: Mon, 25 Mar 2019 15:20:09 +0530 Subject: [PATCH 1/3] MIT licence added --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f72a129 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2010-2019 Google, Inc. http://angularjs.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. From ac120da34ff90b961f6a2f1110839c667b586add Mon Sep 17 00:00:00 2001 From: manishsaraan Date: Mon, 25 Mar 2019 15:20:57 +0530 Subject: [PATCH 2/3] Readme updated and minor code refactor --- README.md | 17 ++++++------ src/GitHubLogin.js | 69 +++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 8beb317..bafa1c0 100644 --- a/README.md +++ b/README.md @@ -8,18 +8,20 @@ React component for [GitHub login](https://developer.github.com/v3/oauth/). ## Usage ```js -import React from 'react'; -import ReactDOM from 'react-dom'; -import GitHubLogin from 'react-github-login'; +import React from "react"; +import ReactDOM from "react-dom"; +import GitHubLogin from "react-github-login"; const onSuccess = response => console.log(response); const onFailure = response => console.error(response); ReactDOM.render( - , - document.getElementById('example') + onFailure={onFailure} + />, + document.getElementById("example") ); ``` @@ -73,11 +75,10 @@ Callback for successful login. An object will be passed as an argument to the ca Callback for errors raised during login. - ## Development ```sh $ npm start ``` -Webpack development server starts at [http://localhost:8080](http://localhost:8080), loading [example/index.html](github.com/checkr/react-facebook-login/tree/master/example/index.html). +Webpack development server starts at [http://localhost:8080](http://localhost:8080). diff --git a/src/GitHubLogin.js b/src/GitHubLogin.js index e70aec3..75f11cc 100644 --- a/src/GitHubLogin.js +++ b/src/GitHubLogin.js @@ -1,66 +1,59 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +import React, { Component } from "react"; +import { func, node, string } from "prop-types"; -import PopupWindow from './PopupWindow'; -import { toQuery } from './utils'; +import PopupWindow from "./PopupWindow"; +import { toQuery } from "./utils"; class GitHubLogin extends Component { static propTypes = { - buttonText: PropTypes.string, - children: PropTypes.node, - className: PropTypes.string, - clientId: PropTypes.string.isRequired, - onRequest: PropTypes.func, - onSuccess: PropTypes.func, - onFailure: PropTypes.func, - redirectUri: PropTypes.string, - scope: PropTypes.string, - } + buttonText: string, + children: node, + className: string, + clientId: string.isRequired, + onRequest: func, + onSuccess: func, + onFailure: func, + redirectUri: string, + scope: string + }; static defaultProps = { - buttonText: 'Sign in with GitHub', - redirectUri: '', - scope: 'user:email', + buttonText: "Sign in with GitHub", + redirectUri: "", + scope: "user:email", onRequest: () => {}, onSuccess: () => {}, - onFailure: () => {}, - } + onFailure: () => {} + }; onBtnClick = () => { const { clientId, scope, redirectUri } = this.props; const search = toQuery({ client_id: clientId, scope, - redirect_uri: redirectUri, + redirect_uri: redirectUri }); - const popup = this.popup = PopupWindow.open( - 'github-oauth-authorize', + const popup = (this.popup = PopupWindow.open( + "github-oauth-authorize", `https://github.com/login/oauth/authorize?${search}`, { height: 1000, width: 600 } - ); + )); this.onRequest(); - popup.then( - data => this.onSuccess(data), - error => this.onFailure(error) - ); - } + popup.then(data => this.onSuccess(data), error => this.onFailure(error)); + }; - onRequest = () => { - this.props.onRequest(); - } + onRequest = () => this.props.onRequest(); - onSuccess = (data) => { + onSuccess = data => { if (!data.code) { - return this.onFailure(new Error('\'code\' not found')); + return this.onFailure(new Error("'code' not found")); } this.props.onSuccess(data); - } + }; - onFailure = (error) => { - this.props.onFailure(error); - } + onFailure = error => this.props.onFailure(error); render() { const { className, buttonText, children } = this.props; @@ -70,7 +63,7 @@ class GitHubLogin extends Component { attrs.className = className; } - return ; + return ; } } From ead3c131cf85fecec38accc29eb01d8cddb99184 Mon Sep 17 00:00:00 2001 From: manishsaraan Date: Mon, 25 Mar 2019 15:23:01 +0530 Subject: [PATCH 3/3] Build and Lint scripts added in readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index bafa1c0..4ed0858 100644 --- a/README.md +++ b/README.md @@ -81,4 +81,16 @@ Callback for errors raised during login. $ npm start ``` +## Build + +```sh +$ npm run build +``` + +## Lint + +```sh +$ npm run lint +``` + Webpack development server starts at [http://localhost:8080](http://localhost:8080).