google_sign_in_with_react
A basic React Component to Integrate Google Signin and One Tap Sign-in in ReactJs
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
- ClientId(Mandatory): Pass your Google ClientId as a prop
EX:
<MyGoogle ClientId="<your client id>" localStorage/>
- localStorage(Optional): Saves the user details to the Browsers Local Storage
EX:
<MyGoogle ClientId="<your client id>" localStorage/>
- 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}/>
- 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"/>
- briefConsoleLog(optional): Pass this prop if you want to see user details in ConsoleLog.
EX:
<MyGoogle ClientId="<your client id>" briefConsoleLog/>
License
MIT © VinodKumarBethi