0

I'm trying to implement google login in my react native application using @react-native-google-signin/google-signin package. I followed all the steps in official documentation:(https://react-native-google-signin.github.io/docs/original). Still facing the error. I'm using Django as the backend and want to implement google login without using Firebase.

Below is my code for the google login implementation: I was follwing this guide: https://peerlist.io/blog/engineering/implementing-google-signin-in-react-native The expected outcome was to have my userInfo saved in my user state variable. But I'm entering the error catch block in GoogleLogin() with error statement:error fetching user info [Error: DEVELOPER_ERROR].

GoogleSignin.configure({
    webClientId:
      'xxxxxxxxxxxx.apps.googleusercontent.com',
    androidClientId:
      'xxxxxxxxxx.apps.googleusercontent.com',
    iosClientId:
      'xxxxxxxxxx.apps.googleusercontent.com',
    scopes: ['profile', 'email'],
  });

  const GoogleLogin = async () => {
    try {
      await GoogleSignin.hasPlayServices();
      const userInfo = await GoogleSignin.signIn();
      return userInfo;
    } catch (error) {
      console.log('error fetching user info', error);
    }
  };

  const handleGoogleLogin = async () => {
    setGLoginLoading(true);
    try {
      const response = await GoogleLogin();
      const {idToken, user} = response;
      setUser(user);

      if (idToken) {
        const resp = await authAPI.validateToken({
          token: idToken,
          email: user.email,
        });
        await handlePostLoginData(resp.data);
      }
    } catch (apiError) {
      setGLoginError(
        apiError?.response?.data?.error?.message || 'Something went wrong',
      );
    } finally {
      setGLoginLoading(false);
    }
  };

Can Anyone help with this please?

7
  • Is that everything you get from the error? Commented Aug 2, 2024 at 13:31
  • Yes that is all, this is the whole statement: error fetching user info', [Error: DEVELOPER_ERROR] Commented Aug 2, 2024 at 17:24
  • I resolved the issue, but sadly can't post the answer here due to apparent answer ban. I'll try in parts: So I've figured out the solution to this issue. Apparently, DEVELOPER_ERROR occur when the SHA-1 certificate and package name you provide while creating the client IDs for your app on google cloud console, are either wrong or the combination of both do not represent your application uniquely on GCP. Basically the combination of both should be unique and correct. Commented Aug 3, 2024 at 7:35
  • To get the package name of your react native application, either checkout your-app\android\app\src\main\AndroidManifest.xml here package='xxx' will be your package name, or go to your-app\android\app\build.gradle here application Id will be your package name. ``` android{ ... defaultConfig { applicationId "com.xxx.yyyy" ... } ... } ``` Commented Aug 3, 2024 at 7:36
  • In case you've been stuck like me and your package name is set to default when you first created your project using a template or default CLI command, you can set your package name while calling the CLI command for project initiation by setting a package-name flag npx @react-native-community/cli@latest init AwesomeProject --package-name=your.custom.packagename. [Reference][1], or you can also do it mannually [Reference1][2], [Reference2][3]. Commented Aug 3, 2024 at 7:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.