Skip to content

Google Sign-In not working on Android #1275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mohdabbas opened this issue Apr 29, 2024 · 12 comments
Closed

Google Sign-In not working on Android #1275

mohdabbas opened this issue Apr 29, 2024 · 12 comments

Comments

@mohdabbas
Copy link

mohdabbas commented Apr 29, 2024

I'm encountering an issue with Google Sign-In in my React Native project. Recently, the Google Sign-In functionality has stopped working on Android devices. Previously, it was functioning correctly, but now when users attempt to sign in with Google, a popup appears to select the Google account, but nothing happens after selecting an account. It's worth noting that Google Sign-In continues to work as expected on iOS devices.

Below, I've provided the relevant code snippet from the GoogleLogin.js file along with the project details. Any assistance in resolving this issue would be greatly appreciated.

// GoogleLogin.js
import { StyleSheet, Text, View, Image, TouchableOpacity, ActivityIndicator, Platform } from "react-native";
import React from "react";
import { COLORS } from "../../theme";
import {
  GoogleSignin,
  statusCodes,
} from '@react-native-google-signin/google-signin';
import { setAccessToken } from "../../store/slices/generalSlice";
import { useDispatch } from "react-redux";
import { useNavigation } from "@react-navigation/native";
import axios from "axios";
import { API_URL } from "../../config/constants";
import { useLoginUserMutation, useSignUpUserMutation } from "../../store/api/api";
import { useToast } from "react-native-toast-notifications";

export default function GoogleLogin() {
  const toast = useToast();

  const [gSignIn, setGSignIn] = React.useState()
  const dispatch = useDispatch()
  const navigation = useNavigation()

  const [signUpUser, { isLoading }] = useSignUpUserMutation()
  const [loginUser, { isLoading: loginLoading }] = useLoginUserMutation();

   const handleLogin = async (body) => {
    try {
      const res = await loginUser(body)
      if (res?.error) {
        toast.show("Identifiants de connexion invalides", {
          type: "warning",
          placement: "bottom",
          duration: 4000,
          offset: 30,
          animationType: "slide-in",
        });
      }
      if (res.data?.access_token) {
        dispatch(setAccessToken(res.data?.access_token))
        navigation.popToTop()
      }
    } catch (e) {
      // Handle error
    }
  };

  const handleSignUp = async (body, loginSeq) => {
    try {
      const res = await signUpUser(body)
      if (res?.error) {
        // Handle error
      }
      // Handle success cases
    } catch (e) {
      // Handle error
    }
  }

  const checkSocialUser = async (props) => {
    const response = await axios.get(`${API_URL}verifySocialUserId`, { params: props })
    return response.data
  }

  const SignIn = async () => {
    try {
      GoogleSignin.configure({
        webClientId: "xxx.apps.googleusercontent.com",
        androidClientId: "xxx-xxx.apps.googleusercontent.com",
        iosClientId: "xxx-xxx.apps.googleusercontent.com"
      })
      await GoogleSignin.hasPlayServices();
      const userInfo = await GoogleSignin.signIn();
      setGSignIn(userInfo);
      if (userInfo.user) {
        const isGoogleUser = await checkSocialUser({ google_user_id: userInfo.user.id })
        if (isGoogleUser && !isGoogleUser.status) {
          handleSignUp({ email: userInfo.user.email, first_name: userInfo.user.givenName, last_name: userInfo.user.familyName, password: userInfo.user.familyName+userInfo.user.id, google_user_id: userInfo.user.id, register_medium: 'google' }, ()=>handleLogin({ email: userInfo.user.email, password: userInfo.user.familyName+userInfo.user.id }))
        } else if (isGoogleUser.status) {
          handleLogin({ email: userInfo.user.email, password: userInfo.user.familyName+userInfo.user.id })
        } else {
          alert("Some error occurred");
        }
      }
    } catch (error) {
      // Handle error
    }
  };

  return (
    <View>
      {(isLoading || loginLoading) ? <ActivityIndicator size={"large"} color={COLORS.primary}/> : <TouchableOpacity style={styles.socialLogin} onPress={() => { SignIn() }}>
        <Image
          source={require("../../assets/icons/google-logo.png")}
          style={styles.socialicon}
        />
        <Text style={styles.socialTxt}>Connecter avec Google</Text>
      </TouchableOpacity>}
    </View>
  );
}

const styles = StyleSheet.create({
  ...
});

Expected Behavior
I expected Google Sign-In to work smoothly on both Android and iOS devices.

Actual Behavior
Google Sign-In is not working on Android devices. When users click "Sign in with Google", a popup appears to select the Google account, but nothing happens after selecting an account.

Environment
react-native version: 0.72.6
@react-native-google-signin/google-signin version: 11.0.1
Expo version: ~49.0.6

Please let me know if you need any further information. Thank you!

@krisbaum74
Copy link

i have exactly the same issue, but its intermittent. I feel more sane now that i see im not the only one.

@mohdabbas
Copy link
Author

Users are facing the issue, but there is no solution available! Strange!

@dbenader
Copy link

dbenader commented May 7, 2024

@mohdabbas completely unrelated, but how is it that you're able to pass androidClientId to GoogleSignIn.configure?

the docs show that that property is not available, and I get an error when I try to include it

@RobledoFootbao
Copy link

Same here. iOS working and Android stopped.

@gasmighassen
Copy link

https://stackoverflow.com/questions/54417232/react-native-google-signin-gives-developer-error
this fix the issue for me

@vonovak
Copy link
Collaborator

vonovak commented May 23, 2024

Hello and thanks for reporting,
if this is an intermittent issue, I don't think there's much I can do about it, so I'm going to close this, but feel free to discuss further.

As for androidClientId - that option is simply ignored by the module.

Thank you 🙂

@vonovak vonovak closed this as completed May 23, 2024
@mohdabbas
Copy link
Author

We were not expecting this answer!

@Miti063
Copy link

Miti063 commented Sep 23, 2024

We are still experiencing this issue, with iOS working fine but only Android being affected. This is leading to customer drop-offs. Can we get support on this, even if it's an intermittent issue, due to the impact it's having on our customers?
One observation all my affected customers are on Android 14v.

@StevenHallLtd
Copy link

https://stackoverflow.com/questions/54417232/react-native-google-signin-gives-developer-error this fix the issue for me

This worked for me, too. However, in my case I did not see the DEVELOPER_ERROR, or any error, until I added this code...

const response = await GoogleSignin.signIn().catch((error: Error) => {
      // By default these errors are completely silent :-/
      console.error(error);
    });

@vonovak am I correct that this error is silenced? If so, then throwing that plus any further clarification would be great! 👍🏼

@vonovak
Copy link
Collaborator

vonovak commented Nov 21, 2024

Hello!
I'm not sure what you mean by error being silenced - if an error is thrown, it's your responsibility as a developer to catch and handle it. The module doesn't silence errors - it throws them.

@IlirEdis
Copy link

Having the same issue here. Following this tutorial, i have registered the OAuth 2.0 Client IDs for iOS, Android and web. I have added all the ID's in supabase Google Auth Provider settings, divided by comma. It works fine on development build but not working in production. It opens the popup to choose the google account and after choosing it it just stays in the login screen and not doing anything. I tried catching any error using adb logcat but i dont get any error there. Any hint please!

@eramudeep
Copy link

Having the same issue here. Following this tutorial, i have registered the OAuth 2.0 Client IDs for iOS, Android and web. I have added all the ID's in supabase Google Auth Provider settings, divided by comma. It works fine on development build but not working in production. It opens the popup to choose the google account and after choosing it it just stays in the login screen and not doing anything. I tried catching any error using adb logcat but i dont get any error there. Any hint please!

same here, i tried to find out with the log cat but nothing found.
mine ios is working fine in debug and release mode, for android only debug is working as expected. In release mode popup opens on choosing account popup disappear and not happens further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants