我生成了一个新的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
.