Reputation: 131
I am trying to use Firebase REST API with Axios on Rect Native project:
No matter what I do... I always receive the same error:
handleLogin = () => {
//alert('trying to login....');
const onSuccess = ({ data }) => {
alert('Success!!!!');
// Set JSON Web Token on success
//setClientToken(data.token);
this.setState({ isLoading: false, isAuthorized: true });
navigation.navigate('Home');
};
const onFailure = (error) => {
alert('Error!!!!');
console.log(error && error.response);
this.setState({ errors: error.response.data, isLoading: false });
};
const signupUser = async () => {
try {
// set the url
const url =
'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=.............';
// request data object
const data = {
email: this.state.email,
password: this.state.password,
returnSecureToken: true,
};
// set the headers
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};
const res = await axios.post(url, data, config);
console.log(res.data);
onSuccess(res.data);
} catch (err) {
console.error(err);
onFailure(err);
}
};
signupUser();
};
I am always receiving error 400 with the same response:
"code": 400, "errors": Array [ Object { "domain": "global", "message": "ADMIN_ONLY_OPERATION", "reason": "invalid",
Does anybody see what I am doing wrong, Thanks!
Upvotes: 0
Views: 1727
Reputation: 131
If anybody need this....
here was a problem:
const config = {
headers: {
'Content-Type': 'application/json',
},
};
Upvotes: 2