I am trying to add a integrate google sign in with firebase, and here is my complete sign in code… I am using expo-google-app-auth package.
isUserEqual = (googleUser, firebaseUser) => {
if (firebaseUser) {
var providerData = firebaseUser.providerData;
for (var i = 0; i < providerData.length; i++) {
if (
providerData[i].providerId ===
firebase.auth.GoogleAuthProvider.PROVIDER_ID &&
providerData[i].uid === googleUser.getBasicProfile().getId()
) {
// We don't need to reauth the Firebase connection.
return true;
}
}
}
return false;
};
onSignIn = (googleUser) => {
console.log("Google Auth Response", googleUser);
// We need to register an Observer on Firebase Auth to make sure auth is initialized.
var unsubscribe = firebase.auth().onAuthStateChanged(
function (firebaseUser) {
unsubscribe();
// Check if we are already signed-in Firebase with the correct user.
if (!this.isUserEqual(googleUser, firebaseUser)) {
// Build Firebase credential with the Google ID token.
var credential = firebase.auth.GoogleAuthProvider.credential(
googleUser.idToken,
googleUser.accessToken
);
// Sign in with credential from the Google user.
firebase
.auth()
.signInWithCredential(credential)
.then(function (result) {
console.log("user signed in");
if (result.additionalUserInfo.isNewUser) {
//add to firebase
} else {
//update user
}
})
.catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
} else {
console.log("User already signed-in Firebase.");
}
}.bind(this)
);
};
signInWithGoogleAsync = async () => {
// console.log("dabdajndajk");
try {
const result = await Google.logInAsync({
// behavior: "web",
androidClientId:
"<CLIENT ID>",
// iosClientId: YOUR_CLIENT_ID_HERE,
scopes: ["profile", "email"],
});
if (result.type === "success") {
this.onSignIn(result);
return result.accessToken;
} else {
return { cancelled: true };
}
} catch (e) {
return { error: true };
}
};
I am Invoking signInWithGoogleAsync() function when the button is pressed.
This method is working in the development but it is not working after the build…
What will be the issue?