How to setup google sign in with react-native-firebase?

  1. Target Platform (e.g. iOS, Android): Android
  2. Development Operating System (e.g. macOS Sierra, Windows 10): Windows 10
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant):
  4. React Native version (e.g. 0.45.1): 0.45
  5. RNFirebase Version (e.g. 2.0.2): 1.1.2

Hello, I’m trying to authenticate with firebase auth using react-native-firebase library but seems like there are lots of issues coming in, I have not initialized webClientId or defined it and what I’m doing right now is that I’m currently sending my accessToken like this:

 GoogleSignin.signIn().then((user) => {
            console.log(user);
            this.setState({user: user});
            console.log(user.token+" token");
            const credential = {
                provider: 'google',
                token: user.accessToken,
                secret: user.id, //I do not know what to send in secret
            };            
            Authentication.googleLogin(credential);
        })
            .catch((err) => {
               alert('WRONG SIGNIN'+ err);
            })
            .done();

and here is my authentication firebase code:

static googleLogin(getCredentials) {
        //this.setState({user: user});
        firebase.auth().signInWithCredential(getCredentials)
            .then((user) => {
                console.log('User successfully signed in', user)
            })
            .catch((err) => {
                console.error('User signin error', err);
            });
    }

Upon running, it throws me this error:

> User signin error Error: An internal error has occurred. [ Unable to parse Google id_token: -accessToken-

And then I did some research on how I can fix this and turns out that some articles said that I need idToken which I do not know how to get, I have not initialized my webClientId yet so that is the reason I think I’m currently getting null at, I do not know how to set that up so I tried to edit my config method like this which did not give me any tokenId:

_configureOauth(clientId, scopes=[]) {
        GoogleSignin.configure(
            "myIdhere", 
            [], // I do not know what to put here either
            "https://my-app.firebaseio.com/auth" //I also tried without auth
        );
}

so after all these attempts and seaching up the whole github I was not able to find any solution so this is the last thing but I since there are 74 issues which are open I don’t think that this will be solved here so easily but please if you know the solution to this please answer. Thank you!

Author: Fantashit

7 thoughts on “How to setup google sign in with react-native-firebase?

  1. You need to build your credential the following way:

    const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);

    So you will need to get idToken from your oauth library of choice

  2. @ShariqMush try using your initialised instance of firebase to access the auth.GoogleAuthProvider using the module one from import firebase from 'react-native-firebase'; won’t work – at least not in v1.1.2.

    e.g:

    import firebase from 'react-native-firebase';
    
    const instance = firebase.intializeApp({
         // your opts
    });
    
    // ...
    const credential = instance.auth.GoogleAuthProvider.credential(idToken, accessToken);

Comments are closed.

How to setup google sign in with react-native-firebase?

  1. Target Platform (e.g. iOS, Android): Android
  2. Development Operating System (e.g. macOS Sierra, Windows 10): Windows 10
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant):
  4. React Native version (e.g. 0.45.1): 0.45
  5. RNFirebase Version (e.g. 2.0.2): 1.1.2

Hello, I’m trying to authenticate with firebase auth using react-native-firebase library but seems like there are lots of issues coming in, I have not initialized webClientId or defined it and what I’m doing right now is that I’m currently sending my accessToken like this:

 GoogleSignin.signIn().then((user) => {
            console.log(user);
            this.setState({user: user});
            console.log(user.token+" token");
            const credential = {
                provider: 'google',
                token: user.accessToken,
                secret: user.id, //I do not know what to send in secret
            };            
            Authentication.googleLogin(credential);
        })
            .catch((err) => {
               alert('WRONG SIGNIN'+ err);
            })
            .done();

and here is my authentication firebase code:

static googleLogin(getCredentials) {
        //this.setState({user: user});
        firebase.auth().signInWithCredential(getCredentials)
            .then((user) => {
                console.log('User successfully signed in', user)
            })
            .catch((err) => {
                console.error('User signin error', err);
            });
    }

Upon running, it throws me this error:

> User signin error Error: An internal error has occurred. [ Unable to parse Google id_token: -accessToken-

And then I did some research on how I can fix this and turns out that some articles said that I need idToken which I do not know how to get, I have not initialized my webClientId yet so that is the reason I think I’m currently getting null at, I do not know how to set that up so I tried to edit my config method like this which did not give me any tokenId:

_configureOauth(clientId, scopes=[]) {
        GoogleSignin.configure(
            "myIdhere", 
            [], // I do not know what to put here either
            "https://my-app.firebaseio.com/auth" //I also tried without auth
        );
}

so after all these attempts and seaching up the whole github I was not able to find any solution so this is the last thing but I since there are 74 issues which are open I don’t think that this will be solved here so easily but please if you know the solution to this please answer. Thank you!

Author: Fantashit

9 thoughts on “How to setup google sign in with react-native-firebase?

  1. You need to build your credential the following way:

    const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);

    So you will need to get idToken from your oauth library of choice

  2. @ShariqMush try using your initialised instance of firebase to access the auth.GoogleAuthProvider using the module one from import firebase from 'react-native-firebase'; won’t work – at least not in v1.1.2.

    e.g:

    import firebase from 'react-native-firebase';
    
    const instance = firebase.intializeApp({
         // your opts
    });
    
    // ...
    const credential = instance.auth.GoogleAuthProvider.credential(idToken, accessToken);
  3. Pingback: replica watch
  4. Pingback: regression testing

Comments are closed.

How to setup google sign in with react-native-firebase?

  1. Target Platform (e.g. iOS, Android): Android
  2. Development Operating System (e.g. macOS Sierra, Windows 10): Windows 10
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant):
  4. React Native version (e.g. 0.45.1): 0.45
  5. RNFirebase Version (e.g. 2.0.2): 1.1.2

Hello, I’m trying to authenticate with firebase auth using react-native-firebase library but seems like there are lots of issues coming in, I have not initialized webClientId or defined it and what I’m doing right now is that I’m currently sending my accessToken like this:

 GoogleSignin.signIn().then((user) => {
            console.log(user);
            this.setState({user: user});
            console.log(user.token+" token");
            const credential = {
                provider: 'google',
                token: user.accessToken,
                secret: user.id, //I do not know what to send in secret
            };            
            Authentication.googleLogin(credential);
        })
            .catch((err) => {
               alert('WRONG SIGNIN'+ err);
            })
            .done();

and here is my authentication firebase code:

static googleLogin(getCredentials) {
        //this.setState({user: user});
        firebase.auth().signInWithCredential(getCredentials)
            .then((user) => {
                console.log('User successfully signed in', user)
            })
            .catch((err) => {
                console.error('User signin error', err);
            });
    }

Upon running, it throws me this error:

> User signin error Error: An internal error has occurred. [ Unable to parse Google id_token: -accessToken-

And then I did some research on how I can fix this and turns out that some articles said that I need idToken which I do not know how to get, I have not initialized my webClientId yet so that is the reason I think I’m currently getting null at, I do not know how to set that up so I tried to edit my config method like this which did not give me any tokenId:

_configureOauth(clientId, scopes=[]) {
        GoogleSignin.configure(
            "myIdhere", 
            [], // I do not know what to put here either
            "https://my-app.firebaseio.com/auth" //I also tried without auth
        );
}

so after all these attempts and seaching up the whole github I was not able to find any solution so this is the last thing but I since there are 74 issues which are open I don’t think that this will be solved here so easily but please if you know the solution to this please answer. Thank you!

Author: Fantashit

2 thoughts on “How to setup google sign in with react-native-firebase?

  1. You need to build your credential the following way:

    const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);

    So you will need to get idToken from your oauth library of choice

Comments are closed.