Expo-google-sign-in doesn't seem to work.

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

async componentDidMount() {
    try {
      await GoogleSignIn.initAsync({
        isOfflineEnabled: true,
        isPromptEnabled: true,
        clientId,
      });
      this._syncUserWithStateAsync();
    } catch ({ message }) {
      alert('GoogleSignIn.initAsync(): ' + message);
    }
  }

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.

1 Like

I am also getting the same issue. Same exact code.

Hi @yunjay and @dpercoco,

I’m recreating this and trying to reproduce the error. From there I’ll talk to Evan about the issue.

Hoping to get back to you soon!

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?

What happens when you do?

import * as GoogleSignIn from 'expo-google-sign-in';
1 Like
Cannot read property 'ERRORS' of undefined
|handleException|@|ExceptionsManager.js:76|
|---|---|---|
|handleError|@|InitializeCore.js:69|
|reportFatalError|@|error-guard.js:42|
|guardedLoadModule|@|require.js:181|
|metroRequire|@|require.js:115|
|(anonymous)|@|blob:http://192.168.…fe131331a67a:155252|
|executeApplicationScript|@|debuggerWorker.js:40|
|(anonymous)|@|debuggerWorker.js:65|

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.

Hi @bacon, did you have time to check on the bug? The solution of @truecar does not work for expo managed apps.

I have followed the exact steps given in the above blog.

Also took app.js from https://github.com/lingonsaft/google-sign-in-expo-create-react-native-app

But clicking on Sign In button gives error…

error [TypeError: undefined is not an object (evaluating ‘_expo.default.Google’)]

The expo SDK version is 32.

Please help. Let me know if google sign in works with OAuth ?

Hi @charliecruzan,

Were you able to reproduce the error?

Thanks in advance

I ran into the issue undefined is not an object (evaluating '_ExpoGoogleSignIn.default.ERRORS').

Try both import * as GoogleSignIn from 'expo-google-sign-in' andimport {GoogleSignIn} from ‘expo-google-sign-in’`

Was somebody able to solve this issue? I have the same problem.

Hello @bacon, any luck resolving this issue? We’re stuck. Help pleeeeeeaaaaaase.

in my app.json

"ios": {
      "supportsTablet": false,
      "bundleIdentifier": "com.blahblah",
      "config": {
        "googleSignIn": {
          "reservedClientId": "myreservedapikey"
        },
      }
    },
    "android": {
      "package": "com.blahblah",
      "googleServicesFile": "./google-services.json"
    }
import { Facebook, GoogleSignIn } from "expo";
try {
      await GoogleSignIn.initAsync({
        clientId:
          "clientId"
      });
    } catch ({ message }) {
      alert("GoogleSignIn.initAsync(): " + message);
    }

The below ones is my code parts on codebase, when I successfully run Facebook Login Graph even in TestFlight, the Google sign in seems not working.

GoogleSignIn.initAsync(): undefined is not an object (evaulating ‘v.GoogleSignIn.initAsync’)

Is there any error on my configurations or just is GoogleSignIn not working ?

edit

Is there any way to use GoogleSignIn without ejecting a expo app?

Hi,

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:

npm install firebase

or

yarn add firebase

then you can follow also https://firebase.google.com/docs/web/setup?hl=es-419

For more, I have this in my loginScreen.js:

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 hope this works for you

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’;

Solved the problem and Google Signin works!!

2 Likes

@bacon , I have used the below code with expo 32 but i am getting error as

login: error:GoogleSignin.askforplayservicesAsync is not a function.

My code is:

import React, { Component } from "react";
import { View, Text, Linking,Button } from "react-native";
import { HeaderNavigationBar } from "../App.js";
import * as GoogleSignIn from 'expo-google-sign-in';


export default class GoogleSSO extends Component {
  state = { user: null };

  componentDidMount(){
    this.initAsync()
  }
  initAsync = async () => {
    await GoogleSignIn.initAsync({
      clientId: 'myclientid',
    });
    this._syncUserWithStateAsync();
  };

  _syncUserWithStateAsync = async () => {
    const user = await GoogleSignIn.signInSilentlyAsync();
    this.setState({ user });
  };

  signOutAsync = async () => {
    await GoogleSignIn.signOutAsync();
    this.setState({ user: null });
  };

  signInAsync = async () => {
    try {
      await GoogleSignIn.askForPlayServicesAsync();
      const { type, user } = await GoogleSignIn.signInAsync();
      if (type === 'success') {
        this._syncUserWithStateAsync();
      }
    } catch ({ message }) {
      alert('login: Error:' + message);
    }
  };

  onPress = () => {
    if (this.state.user) {
      this.signOutAsync();
    } else {
      this.signInAsync();
    }
  }
   
  render() {
    return (
      <View
        style={{
          flex: 1,
          flexDirection: "column"
        }}
      >
        <HeaderNavigationBar {...this.props} />
        <View
          style={{
            flex: 1,
            alignItems: "center",
            justifyContent: "center"
          }}
        >
          <Text onPress={this.onPress}>Toggle Auth</Text>
        </View>
      </View>
    );
  }
}

package.json:

{
  "name": "",
  "main": "node_modules/expo/AppEntry.js",
  "private": true,
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject"
  },
  "dependencies": {
    "axios": "0.18.0",
    "expo": "^32.0.0",
    "firebase": "^5.7.3",
    "install": "^0.12.2",
    "npm": "^6.5.0",
    "qs": "^6.6.0",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "react-native-elements": "0.19.1",
    "react-navigation": "^3.11.0"
  }
}

i have my google-services.json and googleservice-info.plist in my root directory.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.