Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!