3
votes

I have front-end server on nuxt.js and backend in django with django-rest-framework. Can anyone give me example of refreshing jwt token with nuxt-auth local strategy? I was tryed save token in vuex store, but this code return undefined

var dr = await this.$auth
    .loginWith('local', {
      data: {
        username: this.username,
        password: this.password
      }
    })
    .then(response => {
      console.log(response)
    })
    .catch(e => {
      this.error = e + ''
    })
3

3 Answers

0
votes

You can use custom strategy for save refreshToken: https://auth.nuxtjs.org/reference/schemes

auth: {
  strategies: {
    local: { _scheme: '~/app/myCustomLocalStrategy.js', /* ... */ }
  }
}
0
votes

I think the approach will vary depending on what you’re doing on the server. The best advice I can offer is to grab the local strategy that exists in nuxt-auth and create a custom strategy based on it.

Nuxt-auth seems to have some hooks into setting and getting refresh tokens but they aren’t documented or particularly well integrated: there’s no hook to a refresh end point for example.

It’s not ideal, but coming up with something workable is possible. For example, you can hook into the user endpoint in your custom strategy and reauthenticate using the refresh token if the user endpoint throws a 401.

0
votes

You can the local strategy where you can define your endpoint to refresh the authorization token.

Then you declare it as defined here:

refresh_token: {
  prefix: '_refresh_token.'
},