I’ve followed the tutorial on https://blog.expo.io/react-native-google-sign-in-with-expo-d1707579a7ce, and tried connecting with Google Firebase using the demo code on https://github.com/EvanBacon/expo-google-sign-in-demo. I can confirm that the app is connected to Firebase because in Firebase the analytics data shows that 1 user has connected. The code I used was identical to Evan Bacon’s demo except for the google-services.js and other custom configurations. However, when running the app, I got an error triggering the {message} in
which returned:
GoogleSignin.initAsync(): undefined is not an object (evaluating ‘v.GoogleSignIn.initAsync’)
as an alert. I’ve made sure all packages are well installed and well, does anyone know why this error is occurring?
The error occurs on app starting and whenever I try to press the Google sign in button.
I’m having this issue as well. It’s failing at line 93 of Expo.js where it’s trying to return GoogleSignIn.
Object.defineProperty(exports, "GoogleSignIn", {
enumerable: true,
get: function () {
return _expoGoogleSignIn().GoogleSignIn; // <----- Here
}
});
So this must mean that the import is failing here:
function _expoGoogleSignIn() {
const data = require("expo-google-sign-in");
_expoGoogleSignIn = function () {
return data;
};
return data;
}
I was able to succeed with GoogleSignIn by creating a new sample project and following the blog post. But I get the above failure in my production app. My production app was created with the Expo CLI 6months ago, where my sample project was created just this week. That is my only guess as to why one would fail and the other would succeed. Guys above, was your project created recently, or some time ago?
Looks like I may have resolved this issue by adding
pod 'EXGoogleSignIn',
:path => "../node_modules/expo-google-sign-in/ios"
To my iOS Podfile. I noticed this line was added in my successful project, but not my failing project. My successful project was created with current CLI, failing project was created with 6 months ago CLI.
I was getting this issues too, but then I used another tecnique for me to get my google sign in into working properly.
I use an auxiliary object for connecting with firebase which is the one that manages the authentication, so just install the library ‘firebase’ by:
import React, { Component } from 'react';
import { View, Button } from 'react-native';
import Fire from '../objects/Fire';
import {logInConfig} from '../config';
[...]
signInWithGoogleAsync = async () => {
try {
const result = await Expo.Google.logInAsync(logInConfig);
if (result.type === 'success') {
Fire.shared.onSignIn(result);
return result.accessToken;
} else {
return { cancelled: true};
}
} catch (e) {
return { error: true };
}
};
render() {
return (
<View style = {styles.container}>
<Button
title ="Sign In With Google"
onPress={() => this.signInWithGoogleAsync()}
></Button>
</View>
);
}
[...]
Then, as you can see, I call my object Fire which is in charge of all the connections with the database, and I have this:
import firebase from 'firebase';
import 'firebase/firestore';
import {firebaseConfig} from '../config';
[...]
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())) {
return true;
}
}
}
return false;
};
onSignIn = googleUser => {
var unsubscribe = firebase.auth().onAuthStateChanged( firebaseUser => {
unsubscribe();
if (!this.isUserEqual(googleUser, firebaseUser)) {
var credential = firebase.auth.GoogleAuthProvider.credential(
googleUser.idToken,googleUser.accessToken);
firebase.auth().signInAndRetrieveDataWithCredential(credential)
.then(function(result) {
console.log('The user is signed in')
if (result.additionalUserInfo.isNewUser) {
Fire.shared.writeUserInDatabase(result);
// this method is to write all the info of google from the user in my database
} else {
userRef.doc(result.user.uid).update({last_logged_in: Date.now()});
}
}).catch(function(error) {
//this are all the values errore has
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
});
} else {
console.log('User already signed-in Firebase');
}
}
);
};
Of course you could do nothing when I write in my own database, but it is nice to have firebase as your database as well.
I was receiving the same error about “undefined is not an object” when using GoogleSignIn.
Changing:
import GoogleSignIn from ‘expo-google-sign-in’;
To:
import * as GoogleSignIn from ‘expo-google-sign-in’;