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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With