0.1.3 • Published 1 year ago

@rheasmith/react-google-one-tap-login v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React - Google One Tap Login

React wrapper for google one tap authentication

Install

npm install @rheasmith/react-google-one-tap-login

OR

yarn add @rheasmith/react-google-one-tap-login

How to use

As a Hook

import { useGoogleOneTapLogin } from '@rheasmith/react-google-one-tap-login';

useGoogleOneTapLogin({
    onError: error => console.log(error),
    onSuccess: response => console.log(response),
    googleAccountConfigs: {
      client_id: // Your google client id here !!!
    },
  });

As a Component

import React from 'react';
import ReactDOM from 'react-dom';
import GoogleOneTapLogin from '@rheasmith/react-google-one-tap-login';

ReactDOM.render(
  <GoogleOneTapLogin onError={(error) => console.log(error} onSuccess={(response) => console.log(response} googleAccountConfigs={{ client_id: // Your google client id here !!! }} />,
  document.getElementById('root')
);

Add Login Button use id="googlButton"

import React from 'react';
import ReactDOM from 'react-dom';
import GoogleOneTapLogin from '@rheasmith/react-google-one-tap-login';

ReactDOM.render(
  <><div id="googleButton"></div></>,
  document.getElementById('root')
);

Props

NameTypeRequiredDescription
disabledbooleanfalseDisable the login prompt
onErrorcallbackfalseonError : Errornull
onSuccesscallbackfalseonSuccess : GoogleEndpointResponse (See below)
disableCancelOnUnmountbooleanfalseDisable cancelation of one tap login on unmount
googleAccountConfigsobjecttrueGoogle One Tap JS API Reference

*client_id is required in googleAccountConfigs

Google EndPoint Response

More details | Name | Type | |----------------|--------| | iss | string | | sup | string | | azp | string | | aud | string | | iat | string | | exp | string | | name | string | | email | string | | local | string | | picture | string | | given_name | string | | family_name | string | | email_verified | string |