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

215
Visualizações
Integrating login solution but getting error eslint Promise executor functions should not be async no-async-promise-executor

I am trying to integrate a login solution to my vue.app utilising the JWT Authentication plugin.

I have a test solution working, but in my main branch, the eslint version must be newer as I am receiving "Promise executor functions should not be async no-async-promise-executor".

My code within my 'store' adn under my actions is:

login({ commit }, credentials){
  return new Promise(async (resolve, reject) => {
    try {
      const { data }  = await axios.post(`https://mywebsite.com/wp-json/jwt-auth/v1/token`, credentials)
      commit('SET_USER', data)
      resolve(data)
    }catch(e){
      reject(e)
    }
  })
},
validate({ state }) {
  return axios({
    url: `https://mywebsite.com/wp-json/jwt-auth/v1/token/validate`, 
    method: 'post',
    headers: {
      'Authorization': `Bearer ${state.user.token}`
    }
  })
},

I'm just unsure how to rewrite this to remove the error ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You seem to have some misunderstanding of async/await. If you want to async/await, you don't need to wrap it in a Promise object. Instead. use async keyword in the method and apply await inside.

var vm = new Vue({
    methods: {
        async login({ commit }, credentials) {
            try {
                const { data } = await axios.post(
                    `https://mywebsite.com/wp-json/jwt-auth/v1/token`,
                    credentials
                );
                commit("SET_USER", data);
            } catch (err) {
                // eslint-disable-next-line
                console.log(err);
            }
        },
        validate({ state }) {
            return axios({
                url: `https://mywebsite.com/wp-json/jwt-auth/v1/token/validate`,
                method: "post",
                headers: {
                    Authorization: `Bearer ${state.user.token}`,
                },
            });
        },
    },
});
about 4 years ago · Juan Pablo Isaza Relatório
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