I am looking to add a Registration feature to my application that uses react-chat-engine but it's failing with a 403 error.
Error: Request failed with status code 403
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.onloadend (xhr.js:66)
A user should be able to sign up, fill in their details and get logged in with this feature. I found a similar issue here how to make a post request to create new users in react-chat-engine but the solution does not work for me and I don't have the reputation to comment ;).
My code:
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')
}
}
I have intentionally blurred out parts of my private key for obvious reasons. My Private key is valid, I have copied it directly from the dashboard. Also, I am able to add a user manually in the dashboard
What could I be missing?