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

275
Visualizações
JWT returned invalid signature on axios request reactjs

So im trying to create refreshtoken hook in react. and nodejs with express as my backend.

my backend code looks like this

exports.refreshToken = (req, res) => {
  const oldToken = req.headers.authorization.split(" ")[1]
  if(oldToken == null ) return res.status(500).send({message: "Token is empty"})
  console.log(myJwt.refreshSecretKey)
  console.log(oldToken)
  jwt.verify(oldToken, myJwt.refreshSecretKey, (err, user) => {
    if(err)
    res.status(500).send({
      msg: err || "Error on refreshing your token"
    })
    else res.send({ refreshToken: generateRefreshToken() });
  })
};

the problem is when i try this endpoint with Postwoman (chrome extension) its WORK

but when i try with React + axios the server return is

{"msg":{"name":"JsonWebTokenError","message":"invalid signature"}}

here is my react code

import axios from '../api/axios'
import useAuth from './useAuth'


const useRefreshToken = () => {
    const Auth = useAuth()
    const refresh = async () => {
        console.log(Auth.auth.token)
        const response = await axios.get("user/refresh", {
            withCredentials: true,
            headers: {
                Authorization: `Bearer ` + Auth.auth.token
            }
        })
        Auth(prev => {
            console.log(JSON.stringify(prev))
            console.log(response?.data?.refreshToken)
            return {...prev, token: response.data.refreshToken}
        })
        return response.data.refreshToken
    }
  return refresh
  
}

export default useRefreshToken
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I'm sending the wrong access token.

What I send in react is the first created accessToken. not the refreshAccessToken

about 4 years ago · Santiago Gelvez 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