I'm working with Firebase Auth REST API and React Native using Axios and Redux.
I have an action to Sign in with email and password, this is my code:
export function signIn(data){
const request = axios({
method:'POST',
url:SIGNIN,
data:{
email: data.email,
password: data.password,
returnSecureToken:true
},
headers:{
"Content-Type":"application/json"
}
}).then(response => {
return response.data
}).catch( e => {
console.log(e)
return false
});
return {
type: SIGN_IN_USER,
payload: request
}
}
If I insert a credentials with email and password correctly everything is fine.
But if I insert an email with errors I expect an answer as indicated in the documentation by example:
EMAIL_NOT_FOUND: There is no user record corresponding to this identifier. The user may have been deleted.
INVALID_PASSWORD: The password is invalid or the user does not have a password.
USER_DISABLED: The user account has been disabled by an administrator.
But I only receive this answer if I generate some error:
Error: Request failed with status code 400
Nothing like the answers indicated in the documentation.
Can somebody help me? Thanks!!
I'm working with Firebase Auth REST API and React Native using Axios and Redux.
I have an action to Sign in with email and password, this is my code:
export function signIn(data){
const request = axios({
method:'POST',
url:SIGNIN,
data:{
email: data.email,
password: data.password,
returnSecureToken:true
},
headers:{
"Content-Type":"application/json"
}
}).then(response => {
return response.data
}).catch( e => {
console.log(e)
return false
});
return {
type: SIGN_IN_USER,
payload: request
}
}
If I insert a credentials with email and password correctly everything is fine.
But if I insert an email with errors I expect an answer as indicated in the documentation by example:
EMAIL_NOT_FOUND: There is no user record corresponding to this identifier. The user may have been deleted.
INVALID_PASSWORD: The password is invalid or the user does not have a password.
USER_DISABLED: The user account has been disabled by an administrator.
But I only receive this answer if I generate some error:
Error: Request failed with status code 400
Nothing like the answers indicated in the documentation.
Can somebody help me? Thanks!!
Share Improve this question edited Jul 22, 2018 at 8:28 OscarDev asked Jul 22, 2018 at 8:04 OscarDevOscarDev 9771 gold badge15 silver badges40 bronze badges 3- 400 means bad request you probably send malformed data. Or maybe you're using old library and firebase updated the API. Just a guess. – jcubic Commented Jul 22, 2018 at 9:06
- @jcubic But when I make the request with the correct email and password everything is fine. When entering the request with the wrong credentials I expect some error but it always tells me the code 400. I want to think that if the request was wrong when entering the correct credentials I would not have to access it correctly. – OscarDev Commented Jul 22, 2018 at 17:48
- Oh, you need to handle 400 error then, nothing you can do about it if it work with correct password and return 400 or wrong one. – jcubic Commented Jul 23, 2018 at 6:07
2 Answers
Reset to default 16The solution:
console.log(error.response.data.error.message)
I have the solution finally, just check how you have imported your firebaseConfig.js
where you have initialize your firebase.
Most of the case we export default firebaseConfig and import it as a object:
import { firebaseConfig } from './src/config/FirebaseConfig'; // Incorrect
import FirebaseConfig from './src/config/FirebaseConfig'; // Correct Order
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743755695a4501716.html
评论列表(0条)