Using Firebase with Expo: how to properly setup and test Firebase config? -


i trying simple expo react native project can save firebase.

following guide here: https://docs.expo.io/versions/latest/guides/using-firebase.html

step 1: how set these values correctly? find them?

const firebaseconfig = {   apikey: "<your-api-key>",   authdomain: "<your-auth-domain>",   databaseurl: "<your-database-url>",   storagebucket: "<your-storage-bucket>" }; 

i had difficult time figuring out exact details step 1, thought share guidelines, , code test step 2 easily.

i tell you, find each value using number next field, , provide code test it.

const firebaseconfig = {     projectid: "", // 0     apikey: "", // 1     authdomain: "", // 2     databaseurl: "", // 3     storagebucket: "", // 4     messagingsenderid: "", // 5 }; 

all of following steps start project main page (which can reach opening project here).

0, 1:
projectid , apikey can both found clicking on gear icon next overview tab, then project settings. in general tab, see project id, , web api key.

2:
authdomain <projectid>.firebaseapp.com.

3:
databaseurl can found clicking on database tab. should be: https://<projectid>.firebaseio.com/.

4:
storagebucket can found clicking on storage tab. should be: gs://<projectid>.appspot.com/.

5:
messagingsenderid can found clicking on gear icon next overview tab, then project settings. in cloud messaging tab, see sender id.


after these set properly, can test following code:

import react 'react'; import { stylesheet, view, button } 'react-native'; import * firebase 'firebase';  // initialize firebase const firebaseconfig = {     // ... }; firebase.initializeapp(firebaseconfig);  export default class app extends react.component {   render() {     return (       <view style={styles.container}>         <button           onpress={() => updatedb(1, 10, 20)}           title="update db on firebase"         />       </view>      );   } }  function updatedb(userid, fieldvalue1, fieldvalue2) {   firebase.database().ref(userid).set({     field1: fieldvalue1,     field2: fieldvalue2,   }); }  const styles = stylesheet.create({   container: {     flex: 1,     backgroundcolor: '#fff',     alignitems: 'center',     justifycontent: 'center',   }, }); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -