Login with Google - Reactjs
Install React-google-login NPM package.
Open App.js and import GoogleLogin from package
import GoogleLogin from 'react-google-login';
Now just add Google Login button with Client ID
<GoogleLogin
clientId="Your_own_client_ID.googleusercontent.com"
buttonText="Login with Google"
onSuccess={pass}
onFailure={fail}
cookiePolicy={'single_host_origin'}
/>
const fail = (result) =>{
alert(result.error);
}
and for onFailure
const pass = (googleData)=>{
console.log(googleData);
}
import { useState } from 'react';
Const for username
const [username, setusername] = useState();
Const for Email
const [userEmail, setUserEmail] = useState();
const [userpic, setuserpic] = useState();
setusername(googleData.profileObj.name);
setUserEmail(googleData.profileObj.email);
setuserpic(googleData.profileObj.imageUrl);
<img src={userpic}/>
<p><b>{username}</b></p>
<p><b>{userEmail}</b></p>