【发布时间】:2021-10-20 15:57:37
【问题描述】:
我希望在我的使用 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)
用户应该能够注册、填写详细信息并使用此功能登录。我在这里how to make a post request to create new users in 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')
}
}
出于显而易见的原因,我故意模糊了我的部分私钥。我的私钥是有效的,我直接从仪表板复制了它。另外,我可以在仪表板中手动添加用户
我可能会错过什么?
【问题讨论】:
-
这没什么区别,我试了几次。另外,从我上面提到的问题来看,接受的解决方案是小写的,所以这不是问题
标签: reactjs axios react-chat-engine