Search code examples
androidfirebasereact-nativefirebase-authenticationgoogle-signin

I get the error "DEVELOPER_ERROR" when I try to log in via Google on Android


In my app built with React Native and the "react-native-firebase" library I do authentication via Google like this:

import { GoogleSignin, statusCodes } from '@react-native-google-signin/google-signin';
import auth from '@react-native-firebase/auth';

const signInWithGoogle = async () => {
  try {
    GoogleSignin.configure({
      // This is example of webClientId
      webClientId: 'example.apps.googleusercontent.com',
      prompt: 'select_account',
    });

    // Check if your device supports Google Play
    await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });

    // Get the users ID token
    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
    return auth().signInWithCredential(googleCredential);
  } catch (error) {
    if (error.code === statusCodes.SIGN_IN_CANCELLED) {
      alert("Access cancelled");
    } else if (error.code === statusCodes.IN_PROGRESS) {
      alert("The access procedure is already underway");
    } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
      alert("Google Play Services not available");
    } else {
      alert(error.message);
    }
  }
}

If needed you can find the documentation of the two libraries here:

https://www.npmjs.com/package/@react-native-google-signin/google-signin#public-api

https://rnfirebase.io/auth/social-auth#google

My problem is as follows:

Authentication works correctly when I do tests in my computer with the emulator or my phone, while the version of the app I published in the Google Play Store (With obviously the same code) does not log me in. The code generates an exception which is caught in the "else" of my function and the result of the alert with error.message is "DEVELOPER_ERROR".

Why am I having this problem?

(If more information is needed please ask).


Solution

  • How I solved:

    I solved by adding the SHA-1 of the "App Signing Key Certificate" and "Upload Key Certificate" to the firebase project.

    Where do I find the SHA-1 of the "App Signing Key Certificate" and "Upload Key Certificate"?

    Go to Google Play Console and enter your App, in the left section look for "Setup" and then "App Integrity" click on it. Once there, there will be the "Google Play App Signature" item click on "Settings" on the right.

    Here you will find the SHA-1 codes for the "App Signing Key Certificate" and "Upload Key Certificate"

    Now you need to add the two SHA-1s in your Firebase project and update the google.services.json file.

    Go into your Firebase project by clicking on the gear in the left menu and click on "Project Settings," scroll down to "Your Apps" and add the two SHA-1 that you obtained from Google Play Console.

    Once you have added the two SHA-1s re-download the "google.services.json" and replace it with the one you have in your project.

    Once that is done you are done.

    This video is a bit old but can give you a hand on the procedure: https://youtu.be/ZwLitygHsNM?si=e45X0o6yYETv4A3r