Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
Vue.JS POST request pass null bearer token and failed with status code 401

I'm backend guy who wants to gain some Vue.js skills. In my app I've got Ruby on Rails as backend and Vue.js as front-end with a standard JWT token flow. I'm trying to send a POST request (fetchAllProductsRequest) to the backend that will trigger some background job using below code:

index.js

const fetchAllProductsRequest = (self) => {
  const jwtToken = self.$store.state.idToken;

  return axios
    .post(`/api/v1/imports/products/fetch_all`,{
      headers: {
        Authorization: `Bearer ${jwtToken}`,
        'Content-Type': 'application/json',
        'Accept': 'application/json'
      }
    })
    .then(response => response.data)
};

Quite surprisingly I get an error: Request failed with status code 401. When I debugging it on the backend side I see that I send an empty token inside the header:

[1] pry(#<Api::V1::Imports::ProductsController>)> params[:headers]
=> #<ActionController::Parameters {"Authorization"=>"Bearer null", "Content-Type"=>"application/json", "Accept"=>"application/json"} permitted: false> 

Here is a function that triggers fetchAllProductsRequest which is responsible for POST request:

fetch_all.vue

<script>
import {
  fetchAllProductsRequest,
} from '../../api/imports'

import ModalController from '../general/modal_controller'

export default {
  name: 'BackboneFetchAll',
  data() {
    return { }
  },
  components: {
    MoonLoader
  },
  computed: {
    databaseSyncInProgress() {
      return this.$store.getters.getDatabaseSyncStatus;
    },
  },
  methods: {
    async syncAll() {
      let confirmationText = `Do you want to sync all Backbone products?`

      if (await ModalController.showConfirmation('Confirmation', confirmationText)) {
        try {
          ModalController.showLoader()
          await fetchAllProductsRequest(this)
          this.$store.commit('setSyncingProductsInProgress', value)
          const successMessage = `Database synchronization has been queued`
          await ModalController.showToast('', successMessage)
        } catch (data) {
          const errorMessage = `Error occurred during queueing products to sync - `
          ModalController.showToast('', errorMessage + data?.message, 'error')
        } finally {
          ModalController.hideLoader()
        }
      }
    },
  }
}
</script>

What did I missed?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda