2016-08-09 4 views
0

나는 네이티브와 파이어베이스가 서로 작동하도록 노력해 왔지만, 내가 찾는 모든 것이 오래된 튜토리얼이 아닌 것처럼 보입니다. 마침내 firebase 객체를 초기화 할 수 있었을 때, 우리가 다른 튜토리얼에서 사용하고있는 메소드 이름은 내가 정의한 객체로 정의되지 않았습니다. 나는 이것에 약간의 손실이 있습니다. 도움이 될 것입니다. 감사합니다.firebase 로그인을 사용하여 반응하는 방법

import React, { Component } from 'react'; 

import {View} from 'react-native'; 

import * as Firebase from 'firebase'; 

var firebaseConfig = { 
    apiKey: '....', 
    authDomain: '....', 
    databaseURL: 'https://....', 
    storageBucket: '...', 
}; 

Firebase.initializeApp(firebaseConfig, 'unique_id'); 

class LoginProcess extends Component { 
    constructor(props) { 
     super(props); 
     var fbRef = Firebase; 
    } 

    login(email, password) { 
     if (this.props.onLoginRequested) { 
      this.props.onLoginRequested(); 
     } 

     // Firebase.authWithPassword({ 
     // 'email': email, 
     // 'password': password 
     // }, 
     // (error, user_data) => { 
     // if (error) { 
     //  console.log('Login Failed. Please try again'); 
     // } 
     // else { 
     //  AsyncStorage.setItem('user_data', JSON.stringify(user_data)); 
     //  console.log(JSON.stringify(user_data)) 
     // } 
     // }); 
    } 

    render() { 
     return (<View/>) 
    } 
} 

module.exports = LoginProcess; 

답변

1

주위를 놀고 난 후에 나는 이것이 내가 필요한 것을 얻을 수있는 한 가지 방법 이었다는 것을 알았다.

export const loginUser = ({ email, password }) => { 
    return (dispatch) => { 

dispatch({ type: LOGIN_USER }); 

firebase.auth().signInWithEmailAndPassword(email, password) 
    .then(user => loginUserSuccess(dispatch, user)) 
    .catch(() => { 
    firebase.auth().createUserWithEmailAndPassword(email, password) 
     .then(user => loginUserSuccess(dispatch, user)) 
     .catch(() => loginUserFail(dispatch)); 
    }); 
}; 
}; 

const loginUserSuccess = (dispatch, user) => { 
    dispatch({ 
    type: LOGIN_USER_SUCCESS, 
    payload: user 
    }); 
    Actions.main(); 
}; 

나는 또한 궁금 당신이 발견 한 경우 (이미 존재하지 않는 경우에도 사용자를 만듭니다)

import React, { Component } from 'react'; 

import {View} from 'react-native'; 

import * as Firebase from 'firebase'; 

var firebaseConfig = { 
    apiKey: '.....', 
    authDomain: '......', 
    databaseURL: 'https://......', 
    storageBucket: '......', 
}; 

const firebaseApp = Firebase.initializeApp(firebaseConfig, 'unique_id'); 

const auth = firebaseApp.auth(); 

class LoginProcess extends Component { 
    login(email, password) { 
     if (this.props.onLoginRequested) { 
      this.props.onLoginRequested(); 
     } 
     // auth.createUserWithEmailAndPassword // for signup 
     auth.signInWithEmailAndPassword(email, password) 
     .then((data) => { 
      if (this.props.onLoginSuccess) { 
       this.props.onLoginSuccess(data) 
      } 
     }) 
     .catch((error) => { 
      var errorCode = error.code; 
      var errorMessage = error.message; 

      if (this.props.onLoginError) { 
       this.props.onLoginError(error.code, error.message) 
      } 
     }); 
    } 

    render() {return <View/>;} 
} 

module.exports = LoginProcess; 
0

당신은 이미 해결책을 발견,하지만 난 그렇게처럼 돌아 오는에 매여있다 방법을 다시 응용 프로그램을 열 때 로그인 유지하려면?

관련 문제