Coder Social home page Coder Social logo

Comments (2)

Flyrell avatar Flyrell commented on May 22, 2024

Hi Chad,

I'm sorry but I have completely missed your issue.

I didn't even read the whole thing, so correct me if I'm wrong, but it seems like you're missing the return statement in refreshAuthLogic function.

Try returning the axios call, so the interceptor can bind to it.

const refreshAuthLogic = (failedRequest) => {
    console.log('failed request interceptor');

    // unable to refresh because the token is not available
    if (userActions.getRefreshToken() === false) {
        return Promise.reject(failedRequest)
    }

    return api
        .post("/oauth/token", {
            grant_type: "refresh_token",
            refresh_token: userActions.getRefreshToken(),
            client_id: process.env.REACT_APP_CLIENT_ID,
            client_secret: process.env.REACT_APP_CLIENT_SECRET
        })
        .then(tokenRefreshResponse => {
            // save the new access and refresh tokens
            localStorage.setItem(
                "auth-token",
                JSON.stringify(tokenRefreshResponse.data)
            );
            failedRequest.response.config.headers["Authentication"] = "Bearer " + userActions.getAuthenticatedToken();
            return Promise.resolve();
        })
}

from axios-auth-refresh.

drmmr763 avatar drmmr763 commented on May 22, 2024

Hi Flyrell

Thanks for getting back to me. I did figure this out just the other day. You are right, I was missing the return.

The other big problem I was having was this: I had a Laravel backend with CORS configured on certain routes. But the auth route did not have CORS configured correctly. This meant whenever the XHR request failed it failed as a network / browser error not as a catchable error inside the Refresh function.

This helped me work it out:
axios/axios#569 (comment)

Thanks for taking the time to respond and spot the error. This is working for me now and I'm really happy I got it working. It feels like a very clean implementation.

from axios-auth-refresh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.