mardi 19 octobre 2021

axios post request in if condition has no response data react.js

I want api to send otp but when default_2fa is mobile or email.write this code but respone is null even status code is 200 , i do some test on otpcall outside of if statement and the response work well

    const login = (values) => {

     let payload = {
        "input": values.phone_number,
        "password": values.password,
        "user_agent":"postman",
        "client_host":"local"
      }
      service.post_api(loginUrl, payload = payload)
          .then(resp => {
            
              if (typeof resp !== 'undefined') {
                   if (resp.data.result.is_2fa_active) {
                    if (resp.data.result.default_2fa === "authenticator_app") {
                        setAuthenticatorApp(true)
                    }
                    if ( resp.data.result.default_2fa === "mobile" || resp.data.result.default_2fa === "email") {
                        let payloadOtp = {
                            "type": resp.data.result.default_2fa,
                            "input": values.phone_number,
                            "password": values.password,
                        }
                         service.post_api(otpUrl, payloadOtp).then(response => {
                             setEmailOrSmsAuth(true)
                             return response
                        })
                    }
                  }
              }
          })


  }
 ``
when i call this api the otp api statuse code is 200 and payload has all values i want but response is null
please help me what is wrong with my code!

Aucun commentaire:

Enregistrer un commentaire