Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use firebase login with expo

I was following the instructions on Expo's docs, however I was not sure what goes where. I installed firebase using npm. Then the next step is to copy my firebase setup info, which I did from the firebase console.

import * as firebase from 'firebase';

// Initialize Firebase
const firebaseConfig = {
  apiKey: "<YOUR-API-KEY>",
  authDomain: "<YOUR-AUTH-DOMAIN>",
  databaseURL: "<YOUR-DATABASE-URL>",
  storageBucket: "<YOUR-STORAGE-BUCKET>"
};

firebase.initializeApp(firebaseConfig);

But where does this peace of the code go? In root navigation or router? How do I then refer to it in other parts of my app. As you can tell, I'm fairly new to Expo and React-Native, so your help is appreciated.

like image 813
NSCoder Avatar asked Jul 11 '17 06:07

NSCoder


People also ask

How do I log into Firebase with my phone number and password?

Enable Phone Number sign-in for your Firebase project To sign in users by SMS, you must first enable the Phone Number sign-in method for your Firebase project: In the Firebase console, open the Authentication section. On the Sign-in Method page, enable the Phone Number sign-in method.

How do I import Auth to Firebase?

Import firebase and firebase/authimport firebase from "firebase/app"; import "firebase/auth"; Place a FirebaseAuthProvider component at the top level of your app. ( anywhere as long as it's above the other Auth components ). Then use any of the other components anywhere in your component tree.


1 Answers

You have to add all these code inside the main.js file componentDidMount() method. Use the below code for your reference.

class App extends React.Component {
  componentDidMount() {
    const config = {
      apiKey: "<YOUR-API-KEY>",
      authDomain: "<YOUR-AUTH-DOMAIN>",
      databaseURL: "<YOUR-DATABASE-URL>",
      projectId: "<YOUR-PROJECT-ID>",
      storageBucket: "<YOUR-STORAGE-BUCKET>,
      messagingSenderId: "<YOUR-MESSAGING-SENDER-ID>"
    };
    firebase.initializeApp(config);
  }

  render() {
    return (
      <View >

      </View>
    );
  }
}

You have to initialise this once in your main.js that is your root file for your project and in the other screen you can import the firebase component and work on it.

like image 122
Jeffrey Rajan Avatar answered Oct 23 '22 11:10

Jeffrey Rajan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!