Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase API doesn't respond with common error codes using Axios on react native

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!!

like image 778
OscarDev Avatar asked Dec 18 '25 10:12

OscarDev


1 Answers

The solution:

console.log(error.response.data.error.message)

like image 181
OscarDev Avatar answered Dec 19 '25 23:12

OscarDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!