代码之家  ›  专栏  ›  技术社区  ›  Jacob

未经承诺的身份验证

  •  1
  • Jacob  · 技术社区  · 9 年前

    我生成了一个新的Feathers应用程序,然后生成了身份验证。我还没有编辑任何代码。

    我使用create react app生成react客户端,唯一的更改是创建了一个登录组件,尝试对用户进行身份验证:

    import React, { Component } from 'react';
    import client from './feathers';
    
    export default class Login extends Component {
      constructor(props) {
        super(props);
        this.state = {};
      }
    
      componentDidMount() {
        client.authenticate({
          strategy: 'local',
          email: 'feathers@example.com',
          password: 'secret'
        }).then(token => {
          this.setState({ login: true });
        }).catch(error => {
          console.log(error);
          this.setState({ login: false });
        });
      }
    
      render() {
        if (this.state.login === undefined) {
          return <p>Logging in...</p>;
        } else if (this.state.login === true) {
          return <p>Logged in!</p>;
        } else {
          return <p>Not logged in.</p>;
        }
      }
    }
    

    {type: "FeathersError", name: "NotAuthenticated", message: "Invalid login", code: 401, className: "not-authenticated", …}
    

    ./feathers 本质上与中的同一文件相同 daffl's feathers-chat-react .

    1 回复  |  直到 9 年前
        1
  •  0
  •   Jacob    9 年前

    当我实际创建一个用户时,这个问题就不再发生了。我

    • 创建了一个用户
    • 已成功登录
    • 试图以不存在的用户身份登录。

    当我执行最后一步时,验证承诺如期被拒绝,但我的浏览器不再声称我没有捕捉到异常。