使用React Native连接Firebase

时间:2016-09-20 05:36:08

标签: firebase react-native firebase-authentication

我正在尝试将React Native与Firebase连接。我正在使用以下方法连接Firebase。

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


app.authWithPassword({
  "email": "abc@abc.com",
  "password": "abc1234"
}, (error, user_data) => {
  if (error) {
    alert('Login Failed. Please try again');
  } else {
    AsyncStorage.setItem('user_data', JSON.stringify(user_data));
  }
});

但它返回以下错误:

  

app.authWithPassword不是一个函数。

我正在使用Firebase 3.4 和React Native 0.32

1 个答案:

答案 0 :(得分:3)

来自Firebase documentation

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});