P
P
Pan Propan2021-07-29 09:34:32
Vue.js
Pan Propan, 2021-07-29 09:34:32

How to properly populate ScopeKey in Nuxt.JS?

For authorization I use the nuxt-auth module. The documentation says very little about ScopeKey and even less about how to fill it.
Scopes or user roles I want to take from Django. Django can give them to me without any problems. The question is at what point how and where to transfer this field.
nuxt-auth config is like this

auth: {
    strategies: {
      local: {
        scheme: 'refresh',
        localStorage: {
          prefix: 'auth.'
        },
        token: {
          prefix: 'access_token.',
          property: 'access_token',
          maxAge: 86400,
          type: 'Bearer'
        },
        refreshToken: {
          prefix: 'refresh_token.',
          property: 'refresh_token',
          data: 'refresh_token',
          maxAge: 60 * 60 * 24 * 15
        },
        user: {
          property: 'user',
          autoFetch: true
        },
        endpoints: {
          login: { url: '/login', method: 'post'},
          refresh: { url: '/token/refresh/', method: 'post' },
          user: { url: '/user', method: 'get' },
          logout: { url: '/logout', method: 'post'}
        },
      }
    }
  },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Samartsev, 2022-01-21
@webstr-samarcev

I don’t understand either, but I think so:
in the default config

auth: {
    scopeKey: 'scope',
...

It is assumed that the user object has a scope property .
I did something like:
auth: {
   scopeKey: 'role.name',
...

But this is not true, I think, because no matter what I enter in $auth.hasScope('****') it always returns true...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question