验证时反应导航问题

时间:2019-05-22 10:54:37

标签: react-native authentication login react-native-navigation

我正在一个小项目上,使用react native创建一个简单的登录页面和一个仪表板。这个想法只是插入您的用户名和密码-然后-应该使用MongoDB进行身份验证。此后,应用程序应导航到仪表板。事情是,我设法创建了登录页面,并且导航在添加身份验证之前一开始就工作良好。但后来,它按我的预期停止了工作。问题出在这里,正是代码:

我已经尝试将其添加到“提交”功能中,以便您在验证用户身份时直接导航,否则不会。但是,最终我什么也没得到,结果几乎相同。

export default class LoginForm extends Component<{}> {
  constructor(props) {
    super(props),
      (this.state = {
        email: "",
        password: "",
        acc: false
      });
  }
  Submission() {
    fetch("http://10.0.2.2:3000/api/auth", {
      method: "POST",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        email: this.state.email,
        password: this.state.password
      })
    })
      .then(response => response.text())
      .then(responseJson => {
        this.setState({ acc: responseJson });
        console.log(this.state.acc);
        let x = this.state.acc;
        // console.log(x);
        if (x == "true") {
          // console.log("ok")
          this.props.navigation.navigate("Profile");
        }
      });  

问题可能很简单,因为我仍处于起步阶段,但是由于这个问题,我无法继续进行代码。我希望我能找到一些有关如何克服此问题的想法,因为我花了很长时间才能解决它,但我没有。谢谢。

0 个答案:

没有答案
相关问题