0

Here is my config:

auth: {
    plugins: ['~/plugins/auth.js'],
    strategies: {
      local: {
        scheme: 'refresh',
        token: {
          property: 'jwtToken',
        },
        refreshToken: {
          property: 'refreshToken',
          data: 'refreshToken',
        },
        user: false,
        endpoints: {
          login: { url: '/api/account/authenticate', method: 'post' },
          logout: { url: '/api/account/logout', method: 'post' },
          mPassLogout: { url: '/api/account/init-mpass-logout', method: 'get' },
          refresh: {
            url: '/api/account/refresh-token',
            method: 'post',
            data: {
              test: 123,
            },
          },
          user: false,
        },
      },
    },
  },

In refresh endpoint object I want to send refreshToken and token in the data object, how can I implement this? I can't modify the backend apis. The docs says that endpoints just extend the axios options but how can I access the refreshToken and token in this data? Also after request I need to set the new refresh and jwtToken.

Alopwer
  • 611
  • 8
  • 22

1 Answers1

0

I have created a plugin

export default function (app) {
  app.$axios.onRequest((configs) => {
    if (configs.url === 'yourUrlOnRefresh') {
      const bearerToken = app.$auth.strategy.token.get()
      if (bearerToken) {
        const jwtToken = bearerToken.split(' ')[1]
        configs.data.token = jwtToken
      }
    }
  })
}

Alopwer
  • 611
  • 8
  • 22