Firebase登录按钮无响应。不创建新用户或错误

时间:2018-01-18 06:41:41

标签: android reactjs firebase react-native firebase-authentication

所以我对React Native和Windows上的模拟设备都很陌生,但是我在网上接受了教程,并且已经准确地遵循了代码/指令,但由于某种原因,我没有得到任何对 Firebase的响应< / strong>或收到错误消息。 在本教程的这一部分中,我们将设置一个基本表单,并使用Firebase将用户登录到我们的应用程序中。我们已经从之前的应用程序创建了可重用的组件,包括登录按钮。不幸的是,我不认为按钮响应或Firebase没有连接。我已经在Github.com上传了我的代码,这里是存储库和我的代码的链接:

https://github.com/michalladon/authorization

以下是相应的代码片段:

登录表单组件:

import React, { Component } from 'react';
import { Text } from 'react-native';
import firebase from 'firebase';
import { Button, Card, CardSection, Input } from './common';

class LoginForm extends Component {
  state = { email: '', password: '', error: '' }

  onButtonPress() {
    const { email, password } = this.state;

    firebase.auth().signInWithEmailAndPassword(email, password)
      .catch(() => {
        firebase.auth().createUserWithEmailAndPassword(email, password)
        .catch(() => {
          this.setState({ error: 'Authentication Failed.' });
        });
      });
  }

  render() {
    return (
      <Card>
        <CardSection>
          <Input
            placeholder="user@gmail.com"
            label="Email"
            value={this.state.email}
            onChangeText={email => this.setState({ email })}
          />
        </CardSection>
        <CardSection>
          <Input
            secureTextEntry
            placeholder="password"
            label="Password"
            value={this.state.password}
            onChangeText={password => this.setState({ password })}
            style={{ height: 20, width: 100 }}
          />
        </CardSection>
        <Text style={styles.errorTextStyle}>
          {this.state.error}
        </Text>
        <CardSection>
          <Button onPress={this.onButtonPress.bind(this)}>
            Login
          </Button>
        </CardSection>
      </Card>
    );
  }
}

const styles = {
  errorTextStyle: {
    fontSize: 20,
    alignSelf: 'center',
    color: 'red'
  }
};

export default LoginForm;

可重复使用的按钮组件:

import React from 'react';
import { Text, TouchableOpacity } from 'react-native';

const Button = ({ onPress, children }) => {
  const { buttonStyle, textStyle } = styles;

  return (
    <TouchableOpacity onPress={onPress} style={buttonStyle}>
      <Text style={textStyle}>
        {children}
      </Text>
    </TouchableOpacity>
  );
};

const styles = {
  textStyle: {
    alignSelf: 'center',
    color: '#007aff',
    fontSize: 16,
    fontWeight: '600',
    paddingTop: 10,
    paddingBottom: 10
  },
  buttonStyle: {
      flex: 1,
      alignSelf: 'stretch',
      backgroundColor: '#fff',
      borderRadius: 5,
      borderWidth: 1,
      borderColor: '#007aff',
      marginLeft: 5,
      marginRight: 5
  }
};

export { Button };

有谁知道我的问题是什么?我在课堂上查了一些问题并尝试了一些事情,但没有改变。 Firebase没有新用户的记录,我的应用程序在Windows上通过Android Studio在Nexus 5模拟器上运行也没有显示任何错误。任何帮助将不胜感激。

0 个答案:

没有答案