Getting a token from the backend ,when i add every thing this error is showing in my console : My React Authentication is not working. (firebase react) In my console my network authentication is failing. Its telling me cannot post url. This error : var error = new Error(message);
Error: "Request failed with status code 400"
createError createError.js:16
settle settle.js:17
handleLoad xhr.js:61
In Network Response this error is showing :
{
"error": {
"code": 400,
"message": "MISSING_CUSTOM_TOKEN",
"errors": [
{
"message": "MISSING_CUSTOM_TOKEN",
"domain": "global",
"reason": "invalid"
}
]
}
}
In my project I had at this :
axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]', authData)
This is my code :
This is my code :
auth.js :
import axios from 'axios';
import * as actionTypes from './actionTypes';
export const authStart = () => {
return {
type: actionTypes.AUTH_START
};
};
export const authSuccess = (authData) => {
return {
type: actionTypes.AUTH_SUCCESS,
authData: authData
};
};
export const authFail = (error) => {
return {
type: actionTypes.AUTH_FAIL,
error: error
};
};
export const auth = (email, password) => {
return dispatch => {
dispatch(authStart());
const authData = {
email: email,
password: password,
returnSecureToken: true
};
axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]', authData)
.then(response => {
console.log(response);
dispatch(authSuccess(response.data));
})
.catch(err => {
console.log(err);
dispatch(authFail(err));
});
};
};
It seems you are sending your request to the wrong Endpoint. You should use this endpoint for user sign-up:
https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]
And This one for sign-in:
https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[API_KEY]
By the way, don't forget to replace "[API_KEY]" with your project's API key.
P.S.: You can also take a closer look at this official doc:
https://firebase.google.com/docs/reference/rest/auth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With