Search code examples
vue.jsnuxt.jsnuxt-auth

How to access authorization token in @nuxtjs/auth


I am using nuxt js + @nuxjs/auth (4.9.1) to build a project.

The problem is when I use this.$auth.strategy.token.get() to access authorization token the error Cannot read property 'get' of undefined occur.

How can I access authorization token in @nuxtjs/auth?


Solution

  • I'm using a custom strategy defined in nuxt.conf.js as follows :

      auth: {
        strategies: {
          customStrategy: {
            scheme: '~/schemes/customScheme',
            ....
    

    and I can get the token using the following path :

      console.log(this.$auth.$storage._state['_token.customStrategy'])