1

I am trying to sign my user with firebase using Expo google api, but after successfully retrieving the result from :

Expo.Google.logInAsync

And I got an undefined credentials from :

var credential = firebase.auth.GoogleAuthProvider.credential(idToken,accessToken);

with this error

TypeError: undefined is not an object (evaluating_firebase.default.auth.GoogleAuthProvider.credential'

this is my firebase config file:

import * as firebase from 'firebase';
import '@firebase/firestore';
import 'firebase/auth'

var config = {
  apiKey: "fqsdfdsqfdsqdfqsdfqsdf",
  authDomain: "test.firebaseapp.com",
  databaseURL: "https://test.firebaseio.com",
  projectId: "test",
  storageBucket: "test.appspot.com",
  messagingSenderId: "1321564621"
  };
 const Firebase =  firebase.initializeApp(config);
 //const db = firebase.firestore();
export default Firebase;

action/auth/index.js :

import * as Types from "../Types";
import common from "../../common";
import moment from "moment";
import Firebase from "../../config/firebase";
import Reactotron from "reactotron-react-native";
import { Base64 } from "js-base64";
import { AsyncStorage } from "react-native";
import * as Expo from "expo";
import { AccessToken, LoginManager } from 'react-native-fbsdk';    
...
return async dispatch => {
    dispatch({ type: Types.LOADING });
    try {
      const result = await Expo.Google.logInAsync({
        androidClientId: common.API.androidClientId,
        //iosClientId: YOUR_CLIENT_ID_HERE,  <-- if you use iOS
        scopes: ["profile", "email"],
        behavior: "web"
      });
      if (result.type === "success") {


        var { user, name, photoUrl, accessToken, idToken} = result;


        //var credential = googleProvider.credential(idToken,accessToken);
        //var credential = Firebase.auth.signInAndRetrieveDataWithCredential(idToken,accessToken);
        //Reactotron.log("this is our credentials", credential);
        let userCollection = [];
        let checked = false;
        //const currentUser = await Firebase.auth().signInWithCredential(credential);

packages:

"expo-cli" :"2.20.10",
"firebase": "5.9.3",
oflcad
  • 505
  • 2
  • 6
  • 19

1 Answers1

0

Make sure you import it properly.

import Firebase from "./path in firebase"
...

const credential = Firebase.auth.signInAndRetrieveDataWithCredential(idToken, accessToken);
hong developer
  • 13,291
  • 4
  • 38
  • 68