【问题标题】:How do I access the auth information when I use router.get('/me', (res,req) => {})使用 router.get('/me', (res,req) => {}) 时如何访问身份验证信息
【发布时间】:2021-03-10 18:19:55
【问题描述】:

我还没有真正找到这个问题的答案。但是如何让 nuxtjs/auth 与 mysql 一起工作。更具体地说,我想专门让它与 '/me' 路由一起工作。

例如,当您执行以下操作时如何访问“身份验证”信息:

我的前端登录页面

// #/pages/login.vue
this.$auth.loginWith('local', {
    data: {
    email: this.email,
    password: this.password
    }
}

我的后端路由器

// #/api/router/authRouter.js
router.get('/me', (req,res) => {
    // code to check authentication and return the proper object
})

【问题讨论】:

  • 您是否尝试过查看文档? auth.nuxtjs.org/schemes/local.html#options - 你为认证设置了什么端点?
  • 所以 atm 端点是 /login、/me 和 /register。我已经阅读了文档,但我真的不明白

标签: javascript node.js vue.js nuxt.js


【解决方案1】:

别担心。我得到了它的工作......我必须改变

 auth: {
    strategies: {
      local: {
        endpoints: {
          login: { url: 'auth/login', method: 'post', propertyName: 'data.token' },
          user: { url: 'auth/user', method: 'get', propertyName: false },
          logout: false
        }
      }
    },
}

 auth: {
    strategies: {
      local: {
        endpoints: {
          login: { url: 'auth/login', method: 'post', propertyName: 'token' },
          user: { url: 'auth/user', method: 'get', propertyName: false },
          logout: false
        }
      }
    },
}

我的本​​地存储不断收到“Bearer%undefined”而不是“Bearer tokenkeystring”,因为我的登录有效负载返回

{
success: true,
token: 'tokenkeystring'
}

而不是

{
success:true,
data:
  {
    token: 'tokenkeystring'
  }
}

【讨论】:

    猜你喜欢
    • 2017-06-17
    • 2014-03-18
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多