Unable To Get Google Oauth Authentication Working With React Native And Firebase
I'm attempting to get Google OAuth working with Firebase and React Native and can't seem to get everything working together. I'm using the NPM package react-native-google-signin to
Solution 1:
This is how i did it for my app:
import {GoogleSignin} from'react-native-google-signin';
constKEYS = {
// ... // ios and web keys (i'm loading them from my server)
}
login() {
GoogleSignin.hasPlayServices({ autoResolve: true })
.then(() => {
GoogleSignin.configure(KEYS)
.then(() => {
GoogleSignin.signIn()
.then(this.onGoogleLoginSuccess)
.catch(error=>{})
.done();
});
})
.catch((err) => {
console.log("Play services error", err.code, err.message);
})
}
onGoogleLoginSuccess(user) {
var token = user.idToken;
var provider = firebase.auth.GoogleAuthProvider;
var credential = provider.credential(token);
firebase.auth().signInWithCredential(credential)
.then((data)=>console.log('SUCCESS', data))
.catch((error)=>console.log('ERROR', error));
}
The point is to use signInWithCredential()
method. Reference: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithCredential
Post a Comment for "Unable To Get Google Oauth Authentication Working With React Native And Firebase"