【问题标题】:How to access authorization token in @nuxtjs/auth如何在@nuxtjs/auth 中访问授权令牌
【发布时间】:2021-10-18 00:29:30
【问题描述】:

我正在使用 nuxt js + @nuxjs/auth (4.9.1) 来构建一个项目。

问题是当我使用this.$auth.strategy.token.get() 访问授权令牌时出现错误Cannot read property 'get' of undefined

如何在@nuxtjs/auth 中访问授权令牌?

【问题讨论】:

  • 你使用哪种策略?
  • 我只使用了一种策略。 local
  • 试试 this.$auth['local'].token.get() 坚果我不知道。注销 this.$auth 并查找您需要的内容
  • 返回错误:Cannot read property 'token' of undefined

标签: vue.js nuxt.js nuxt-auth


【解决方案1】:

我正在使用 nuxt.conf.js 中定义的自定义策略,如下所示:

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

我可以使用以下路径获取令牌:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多