google_sign_in_with_react

1.1.2 • Public • Published

google_sign_in_with_react

A basic React Component to Integrate Google Signin and One Tap Sign-in in ReactJs

NPM JavaScript Style Guide

Install

npm install --save google_sign_in_with_react

Prerequisites

This package needs Google's scripts to be in your index.html. So, include the following script in your index.html file.

<script type="text/javascript" src="https://accounts.google.com/gsi/client"></script>

Usage

import React, { Component } from 'react'

import MyGoogle from 'google_sign_in_with_react'
import 'google_sign_in_with_react/dist/index.css'

class Example extends Component {
  render() {
    return <MyGoogle ClientId="<your client id>" localStorage/>
  }
}

Props to be passed

  1. ClientId(Mandatory): Pass your Google ClientId as a prop

EX:

<MyGoogle ClientId="<your client id>" localStorage/>
  1. localStorage(Optional): Saves the user details to the Browsers Local Storage

EX:

<MyGoogle ClientId="<your client id>" localStorage/>
  1. handleResponse(Optional): A callback function is to passed in handleResponse prop

EX:

let handleCallback=(response)=>{
  console.log(response);
}
<MyGoogle ClientId="<your client id>" handleResponse={handleCallback}/>
  1. redirect(optional): Pass a path in redirect prop if you want to naviagte to another route(uses React useNavigate).

EX:

<MyGoogle ClientId="<your client id>" redirect="/profile"/>
  1. briefConsoleLog(optional): Pass this prop if you want to see user details in ConsoleLog.

EX:

<MyGoogle ClientId="<your client id>" briefConsoleLog/>

License

MIT © VinodKumarBethi

Package Sidebar

Install

npm i google_sign_in_with_react

Weekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

14.7 kB

Total Files

7

Last publish

Collaborators

  • bethivinodkumar