Error in CEP function

Asked

Viewed 47 times

0

Hello, I have an application in VUE JS, but when I search the zip code it does not send the data to the API, giving the following error:

PUT http://localhost:xxx/join-user/change 401 (Attempted to perform an unauthorized Operation)

When I put manual no error is shown.

Metodo do do Buscacep:

buscaCep: function () {
  if (this.user.address.zipCode === undefined || this.user.address.zipCode.length <= 7) {
    return null
  }

  this.$store
    .dispatch(GET_ZIPCODE, this.user.address.zipCode)
    .then(({ data }) => {
      var self = this

      if (self.address.erro) {
        return
      }

      self.user.address.name = self.address.logradouro
      self.user.address.district = self.address.bairro

      var state = self.states.filter(x => {
        return x.shortName.toLowerCase().indexOf(self.address.uf.toLowerCase()) > -1
      })

      self.user.address.state.id = state[0].id
      self.changeState()

      setTimeout(function () {
        self.cities.forEach(function (result) {
          if (result.name.toLowerCase() === self.address.localidade.toLowerCase() && result.state.id === self.user.address.state.id) {
            self.user.address.city.id = result.id
          }
        })
      }, 200)
    })
}

It is called on @Blur.Native="buscaCep()"

Method that returns the error:

update () {
  var self = this

  self.$validator.validateAll()
    .then((result) => {
      if (!result) {
        return
      }

      self.$store
        .dispatch(REGISTER_USER_UPDATE)
        .then(() => {
          self.$swal.fire(
            'Sucesso!',
            'Dados salvos com sucesso!',
            'success'
          )
          self.$router.push({ name: 'profile-kennel' })
        })
    })
}

Thank you in advance

  • Cors problem?

  • No, I just downloaded the extension and tested, the error continues.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.