反应本机Facebook登录到黑屏

时间:2020-04-15 05:23:58

标签: react-native facebook-javascript-sdk

我正在尝试将Facebook登录与react native和firebase集成。

开始似乎有效,但随后出现黑屏...

FB login flow

那么,请问我的逻辑中缺少什么?

export default class App extends React.Component {
  constructor(props) {
    super(props);
    //check if logged in
    f.auth().onAuthStateChanged(function (user) {
      if (user) {
        //logged in
        console.log('*** logged in', user);
      } else {
        //logged out
        console.log('*** logged out');
      }
    });
  }

  async loginWithFacebook() {
    await Facebook.initializeAsync('2345');
    const {
      type,
      token
    } = await Facebook.logInWithReadPermissionsAsync({
      permissions: ['email', 'public_profile'],
    });
    if (type === 'success') {
      const credentials = f.auth.FacebookAuthProvider.credential(token);
      f.auth().signInWithCredential(credentials).catch((error) => {
        console.log(`Facebook Login Error: ${error}`);
      })
    }
  }

  registerUser = (email, password) => {
    console.log(email, password);
    auth.createUserWithEmailAndPassword(email, password)
      .then((userObj) => console.log(email, password, userObj))
      .catch((error) => console.log('errore:', error));
   }

  render() {
    return (
      <View style={styles.container}>
        <Text>MaKo Open up App.js to start working on your app!</Text>
        <TouchableHighlight
          onPress={() => this.loginWithFacebook()}
      style={{ backgroundColor: 'green' }}>
      <Text style={{ color: 'white' }}>Login with FB</Text>
    </TouchableHighlight>
  </View>
    );
  }
}

0 个答案:

没有答案