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?
error fetching user info', [Error: DEVELOPER_ERROR]DEVELOPER_ERRORoccur when theSHA-1 certificateandpackage nameyou 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.package nameof your react native application, either checkoutyour-app\android\app\src\main\AndroidManifest.xmlherepackage='xxx'will be your package name, or go toyour-app\android\app\build.gradlehere application Id will be your package name. ``` android{ ... defaultConfig { applicationId "com.xxx.yyyy" ... } ... } ```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].