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

195
Visualizações
Receiving 'jwt malformed' message when trying to load my website initially with Redux

Upon login I have my initial component that calls a Redux action but after logging in the user token isn't sent fast enough to be received by the axios header, if I console.log(token) before and after the axios.create({ headers: auth: token }) it shows null, so of course I'm going to get 'jwt malformed' but how can I set up my app to wait for the token to load before running the Redux file? I've tried a check before running my dispatch to make sure there is a token but the file is running even before that is hit.

// Shoes component
useEffect(() => {
    const { sortby } = props;
    dispatch(getShoesAsync(sortby)).then((response) => {
      setLoading(false);
    });
  }, [dispatch, props]);

//Redux token auth
const userTokenAxios = axios.create({
  baseURL: '/api/shoes',
  headers: {
    Authorization: `Bearer ${localStorage.getItem('token')}`,
  },
});

// Redux action
export const getShoesAsync = createAsyncThunk(
  'shoes/getShoesAsync',
  async (payload, { rejectWithValue }) => {
    try {
      const response = await userTokenAxios.get(`?sortby=${payload}`);
      return response.data;
    } catch (error) {
      return rejectWithValue(error.response.data);
    }
  }
);
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