Authentication with Google

In the same way, we can configure Google authentication in our application; just add the following code into the authWithGoogle() method, and it will open the popup for login with Google:

 authWithGoogle(){
console.log("Google");
googleProvider.addScope('profile');
googleProvider.addScope('email');
firebaseApp.auth().signInWithPopup(googleProvider).then((result,error)=>{
if(error){
console.log("unable to sign in with google");
}
else{
this.setState({redirect:true,data:result.user})
}}).catch((error)=>{
ToastDanger(error.message);
})
}

As you can see, I have added the additional OAuth 2.0 scopes that we want to request from the auth provider. To add a scope, call add the scope. We can also define the language code with firebase.auth().languageCode = 'pt';. If we want to send a specific custom parameter with the request, we can call the setCustomParamter() method. Consider this example:

provider.setCustomParameters({
'login_hint': 'admin'
});

So, once you click on the Login with Google button, it will trigger the popup to authenticate with Google:

So if you are already logged in and try to log in with the same email ID with different providers, it throws errors, as illustrated:

Okay, so now let's see how we can handle these types of errors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset