npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-google-login-logout

v2.9.3

Published

A Google Login Component for React

Downloads

12

Readme

React Google Login

A Google oAUth Sign-in / Log-in Component for React

Install

npm install react-google-login

How to use

import React from 'react';
import ReactDOM from 'react-dom';
import GoogleLogin from 'react-google-login';

const responseGoogle = (response) => {
  console.log(response);
}

ReactDOM.render(
  <GoogleLogin
    clientId="658977310896-knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com"
    buttonText="Login"
    onSuccess={responseGoogle}
    onFailure={responseGoogle}
  />,
  document.getElementById('googleButton')
);

onSuccess callback

If responseType is not 'code', callback will return the GoogleAuth object.

If responseType is 'code', callback will return the offline token for use on your server.

If you use the hostedDomain param, make sure to validate the id_token (a JSON web token) returned by Google on your backend server:

  1. In the responseGoogle(response) {...} callback function, you should get back a standard JWT located at response.hg.id_token
  2. Send this token to your server (preferably as an Authorization header)
  3. Have your server decode the id_token by using a common JWT library such as jwt-simple or by sending a GET request to https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=YOUR_TOKEN_HERE
  4. The returned decoded token should have an hd key equal to the hosted domain you'd like to restrict to.

Logout

Use GoogleLogout button to logout the user from google.

    import GoogleLogout from 'react-google-login';
    <GoogleLogout
      buttonText="Logout"
      onLogoutSuccess={logout}
    >
    </GoogleLogout>

Parameters

| params | value | default value | description | |:------------:|:--------:|:------------------------------------:|:----------------:| | clientId | string | REQUIRED | | | hostedDomain | string | - | | | scope | string | profile email | | | responseType | string | permission | Can be either space-delimited 'id_token', to retrieve an ID Token + 'permission' (or 'token'), to retrieve an Access Token, or 'code', to retrieve an Authorization Code. | onSuccess | function | REQUIRED | | | onFailure | function | REQUIRED | | | onRequest | function | - | | | buttonText | string | Login with Google | | | className | string | - | | | style | object | - | | | disabledStyle| object | - | | | loginHint | string | - | | | prompt | string | - | | | tag | string | button | sets element tag (div, a, span, etc | | autoLoad | boolean | false | | | fetchBasicProfile | boolean | true | | | disabled | boolean | false | | | discoveryDocs | - | https://developers.google.com/discovery/v1/using | | uxMode | string | popup | The UX mode to use for the sign-in flow. Valid values are popup and redirect. | | redirectUri | string | - | If using ux_mode='redirect', this parameter allows you to override the default redirect_uri that will be used at the end of the consent flow. The default redirect_uri is the current URL stripped of query parameters and hash fragment. | | isSignedIn | boolean | false | If true will return GoogleUser object on load, if user has given your app permission |

##Google Scopes List: https://developers.google.com/identity/protocols/googlescopes

onSuccess callback ( w/ offline false)

onSuccess callback returns a GoogleUser object which provides access to all of the GoogleUser methods listed here: https://developers.google.com/identity/sign-in/web/reference#users .

You can also access the returned values via the following properties on the returned object.

| property name | value | definition | |:-------------:|:--------:|:------------------------------------:| | googleId | string | Google user ID | | tokenId | string | Token Id | | accessToken | string | Access Token | | tokenObj | object | Token details object | | profileObj | object | Profile details object |

onSuccess callback ( w/ offline true)

| property name | value | definition | |:-------------:|:--------:|:------------------------------------:| | code | object | offline token |

You can also pass child components such as icons into the button component.

  <GoogleLogin
    clientId={'658977310896-knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com'}
    onSuccess={responseGoogle}
    onFailure={responseGoogle}
  >
    <FontAwesome
      name='google'
    />
    <span> Login with Google</span>
  </GoogleLogin>

onFailure callback

onFailure callback is called when either initialization or a signin attempt fails.

| property name | value | definition | |:-------------:|:--------:|:------------------------------------:| | error | string | Error code | | details | string | Detailed error description |

Common error codes include:

| error code | description | |:----------:|:-----------:| | idpiframe_initialization_failed | initialization of the Google Auth API failed (this will occur if a client doesn't have third party cookies enabled) | | popup_closed_by_user | The user closed the popup before finishing the sign in flow.| | access_denied | The user denied the permission to the scopes required | | immediate_failed | No user could be automatically selected without prompting the consent flow. |

More details can be found in the official Google docs:

Dev Server

npm run start

Default dev server runs at localost:8080 in browser. You can set IP and PORT in webpack.config.dev.js

Run Tests

npm run test:watch

Production Bundle

npm run bundle
Checkout my other login: React Instagram Login
Checkout keppelen's React Facebook Login

Follow me on Twitter: @anthonyjgrove