0

My issue is as follows:

After logging in my acces token and refresh token are stored and I can access them with this.$auth.strategy.token.get()

When my access token is expired, my app calls the /token/refresh endpoint that I created in my backend. However, instead of sending the refresh_token, nuxt auth uses the expired access token. How do I tell Nuxt auth to use the refresh token by default?

My nuxt.config.js:

auth: {
    localStorage: false,
    redirect: {
        login: "/login/",
        logout: "/",
        home: "/search/",
    },
    watchLoggedIn: true,
    strategies: {
        local: {
            scheme: 'refresh',
            token: {
                property: 'access_token',
                global: true
            },
            refreshToken: {
                property: 'refresh_token',
                data: 'refresh_token',
                tokenRequired: true,
                maxAge: 60 * 60 * 24 * 30,
                grantType: 'refresh_token'
               
            },
            user:{
                property: false,
                // autoFetch: false
            },
            endpoints: {
                login: { url: '/login', method: 'post' },
                refresh: { url: '/token/refresh', method: 'get', grant_type:'refresh_token'},
                logout: false,
                user: { url: '/currentuser', method: 'get', propertyName: false }
            },
            tokenRequired: true,
            tokenType: 'Bearer',
        }
    }
}
Mani Mirjavadi
  • 973
  • 9
  • 19
Jochem
  • 31
  • 6
  • 1
    I've achieved to make this one work by having a middleware and in case of an auth error, send the request with the refresh token. – kissu Apr 07 '22 at 13:15
  • I used axios interceptors and figured out the refresh token is sent with the request. Just not in the header, but in the data part. In my config the refresh endpoint has the GET method. I changed that to POST and I altered my backend to get the refresh token from the body. This is a quick fix for now. – Jochem Apr 08 '22 at 08:47

0 Answers0