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

235
Views
baseQueryWithReauth not handling 401 errors, also noticed the prepareHeaders returns an empty object
const baseQuery = fetchBaseQuery({
    baseUrl: 'url',
    prepareHeaders: (headers, { getState }) => {
    const token = getState().auth.token

    // If we have a token set in state, let's assume that we should be passing it.
    if (token) {
      headers.set('authorization', `Bearer ${token}`)
    }

    return headers
  }
})



const baseQueryWithReauth = async (args, api, extraOptions) => {

    let result = await baseQuery(args, api, extraOptions)

    if (result?.error?.originalStatus === 401) {
     //I noticed result.error.originalStatus always returned undefine
      
        console.log('sending refresh token')
        const refreshResult = await baseQuery({
            url: '/users/generateTokens',
            method: 'POST'
          }, api, extraOptions)
        console.log(refreshResult)
        if (refreshResult?.data) {
            const user = api.getState().auth.user
            api.dispatch(setCredits({ ...refreshResult.data, user }))
            result = await baseQuery(args, api, extraOptions)
            console.log(result)
        } else {
            api.dispatch(logOut())
        }
    } 

    return result 
} 
about 4 years ago · Juan Pablo Isaza
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!