Any way to use Firebase google authentication in expo (create-react-native-app) without "eject" project

Noer Nova picture Noer Nova · Jun 18, 2017 · Viewed 7.4k times · Source

As the question, for Login with google in firebase need to set google-service but if you create new react-native project with create-react-native-app there will have no "android" or "ios" folder (accept used "eject") so, anyone have a suggestion for me? However I've no idea for how to setting google-service in my project too (even I "eject" the project).

Answer

Joe Roddy picture Joe Roddy · May 17, 2018

@brentvatne 's answer is a bit out of date. Here's how I got it working on Expo v27

Important bit: you can get your client ids with these instructions.

Just select your firebase app from the project dropdown on the google page.

const _loginWithGoogle = async function() {
  try {
    const result = await Expo.Google.logInAsync({
      androidClientId:"YOUR_ANDROID_CLIENT_ID",
      iosClientId:"YOUR_iOS_CLIENT_ID",
      scopes: ["profile", "email"]
    });

    if (result.type === "success") {
      const { idToken, accessToken } = result;
      const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);
      firebase
        .auth()
        .signInAndRetrieveDataWithCredential(credential)
        .then(res => {
          // user res, create your user, do whatever you want
        })
        .catch(error => {
          console.log("firebase cred err:", error);
        });
    } else {
      return { cancelled: true };
    }
  } catch (err) {
    console.log("err:", err);
  }
};