3

I am implementing firebase social login in my react native app, this problem it has been asked many times and I have followed all what in other question but nothing worked at all, here what I did:

  1. generate Certificate fingerprint from my project based on this docs using cd/android && ./gradlew signingReport and copy SHA1 of the following Variant information:

Variant: debug Config: debug Store: C:\Users\USER-NAME\PROJECT-NAME\android\app\debug.keystore then paste it in firebase under my registered android app.

  1. Download json file and added it to Android/app Directory
  2. Enable google sign In provider in firebase.

4.I have checked the oauth_client/client_id in json file which same is the auto generated one in google console OAuth 2.0 Client IDs

  1. I have added support email in firebase public project information.

  2. all required pre setup for firebase has been done based on this docs

  3. package name when create new app in firebase is same as the name in AndroidManifest.xml

  4. In OAuth in google developers console the app name is same as the name in AndroidManifest.xml

  5. I have rebuild the app several times but still the error occurs.

my code looks like the following:

googleLogin: async () => {
                try {
                    GoogleSignin.configure({
                        webClientId: "542246894154-fgfa3e4b3maonkftkvkd1lvrueda7iop.apps.googleusercontent.com",
                        offlineAccess: true
                    });
                    const data = await GoogleSignin.signIn();
                    const credential = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken);
                    const firebaseUserCredential = await auth().signInWithCredential(credential);
                    if (firebaseUserCredential) setLoggedInGoogle(true);
                    if (typeof success === 'function') success();

                } catch (error) {
                    if (error.code === statusCodes.SIGN_IN_CANCELLED) {
                        // when user cancels sign in process,
                        Alert.alert('Process Cancelled')
                    } else if (error.code === statusCodes.IN_PROGRESS) {
                        // when in progress already
                        Alert.alert('Process in progress')
                    } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
                        // when play services not available
                        Alert.alert('Play services are not available')
                    } else {
                        // some other error
                        Alert.alert('Something else went wrong... ', error.toString())
                        setError(error)
                    }
                }


            }

I will really appreciate any help as I am stuck in this almost 4 hours with same error.

anie
  • 399
  • 5
  • 17
  • I have the same error, Tried for 2days. It seems to be a new issue I think – Thanveer Shah Mar 07 '21 at 18:40
  • 1
    @ThanveerShah i have solved it by creating WebClient id in google developers counsel , then i added the id and secret key to firebase google provider setting then re download the google json file and it worked for me after days of suffering – anie Mar 07 '21 at 18:46
  • That's awsomee, I'll try again and see. I'm sure I'v already done it but maybe this time I'll be more cautious. You dint had to use the SHA-1 ? – Thanveer Shah Mar 07 '21 at 18:50
  • you have to add the SHA-1 @ThanveerShah – anie Mar 07 '21 at 18:55
  • 1
    follow this article it is really so helpful all the problem you may face you will find the solution in it https://www.pradipdebnath.com/2020/10/06/how-to-implement-google-login-in-react-native-with-firebase/ – anie Mar 07 '21 at 18:56
  • I'll look into this article, Thank you so much, You're awsome. – Thanveer Shah Mar 07 '21 at 19:34
  • @ThanveerShah you are welcome – anie Mar 07 '21 at 19:35
  • Faced the same issue. This worked for me. :) https://stackoverflow.com/a/67968820/4913153 – Arun AK Jun 14 '21 at 10:51

1 Answers1

0
  1. Execute the following: keytool -list -v -keystore {/Volumes/Development/Sample/Authentication/android/app/debug.keystore} -alias androiddebugkey -storepass android -keypass android (include your own debug.keystore path)
  2. Copy the SHA-1 key and paste in firebase fingerprint of android
  3. Check the web client Id from the google developer console. It should be same in firebase and as well in code of
GoogleSignin.configure({
   webClientId: '',
});
  1. After doing it, download a new googleService.json file and paste android->app
  2. Finally the function
const OnGoogleSignin = async () => {
    try {
        const { idToken } = await GoogleSignin.signIn();

        // Create a Google credential with the token
        const googleCredential = Auth.GoogleAuthProvider.credential(idToken);

        // Sign-in the user with the credential
        await Auth().signInWithCredential(googleCredential);
    } catch (e) {
        console.log('googleLoginError', e);
    }
};
BRO_THOM
  • 824
  • 9
  • 24