2016-09-20 125 views
1

我試圖將React Native與Firebase連接起來。我正在使用以下方法連接Firebase。將Firebase與React Native連接

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": "[email protected]", 
    "password": "abc1234" 
}, (error, user_data) => { 
    if (error) { 
    alert('Login Failed. Please try again'); 
    } else { 
    AsyncStorage.setItem('user_data', JSON.stringify(user_data)); 
    } 
}); 

但它返回以下錯誤:

app.authWithPassword is not a function.

我使用火力地堡3.4和應對本土0.32

+0

嘗試'firebase.authWithPassword',而不是'app.authWithPassword' – Cherniv

回答

3

Firebase documentation

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