Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 671
Noer Nova Avatar asked Jun 18 '17 15:06

Noer Nova


2 Answers

@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);
  }
};
like image 139
Joe Roddy Avatar answered Oct 18 '22 11:10

Joe Roddy


It isn't necessary to make any changes to the android or ios folders in order to support Google sign in with firebase on an app built with Expo.

  1. Follow the guide for configuring Google auth on the Expo docs
  2. Use the approach described in Expo's Using Firebase guide, where it describes how to authenticate with Facebook, and swap out Google where needed.
like image 40
brentvatne Avatar answered Oct 18 '22 09:10

brentvatne