我希望向使用 react-chat-engine 的应用程序添加注册功能,但由于 403 错误而失败。
Error: Request failed with status code 403
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.onloadend (xhr.js:66)
用户应该能够注册、填写详细信息并使用此功能登录。我在这里发现了一个类似的问题,如何发出帖子请求以在 react-chat-engine 中创建新用户,但该解决方案对我不起作用,我没有评论的声誉;)。
我的代码:
const SignupForm = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [firstname, setFirst] = useState('');
const [lastname, setLast] = useState('');
const [error, setError] = useState('');
// function to handle the submit
const handleSubmit = async (e) => {
e.preventDefault();
//header for authentication
const authObject = {'Private-Key': '4922e43b-xxxxx-xxxx'}
// post request to create user
try {
await axios.post('https://api.chatengine.io/users/',
{ headers: authObject,
body: {
'username': username,
'secret': password
}
});
// login the user
localStorage.setItem('username', username)
localStorage.setItem('password', password)
window.location.reload()
} catch (error) {
console.log(error)
setError('Incorrect credentials, try again')
}
}
出于显而易见的原因,我故意模糊了我的部分私钥。我的私钥是有效的,我直接从仪表板复制了它。此外,我可以在仪表板中手动添加用户
我会错过什么?