javascript - nuxt 认证模块 "User Data response does not contain field XXX"

标签 javascript nuxt.js nuxt-auth

我正在尝试使用 nuxt-auth 模块,我对这个模块的设置是

  auth: {
    cookie: false,
    plugins: ['~/plugins/api.js'],
    redirect: {
      logout: '/login',
      login: '/',
      home: false
    },
    strategies: {
      local: {
        scheme: 'refresh',
        token: {
          property: 'token',
          maxAge: 3600
        },
        refreshToken: {
          property: 'refresh_token',
          data: 'refresh_token',
          maxAge: 60 * 60 * 24 * 30
        },
        user: {
          property: 'userDetail'
        },
        endpoints: {
          login: { url: 'http://localhost:8085/api/login_check', method: 'post', propertyName: 'token' },
          refresh: { url: 'http://localhost:8085/api/token/refresh', method: 'post', propertyName: 'refresh_token' },
          logout: false,
          user: { url: 'http://localhost:8085/api/user/fetchactive', method: 'get' }
        },
        tokenRequired: true
      }
    }
  }

我的“fetchactive”API 返回一个包含属性“userDetail”的 JSON,它是一个包含电子邮件地址的字符串(我也尝试将 userDetail 设为对象,但没有成功)。

例如


{"userDetail":{"email":"my@email.test"}}

Nuxt auth 一直告诉我“用户数据响应不包含字段 userDetail”。

我还尝试将“property”设置为 false,但在这种情况下 Nuxt auth 会查找名为“false”的字段... 我只是无法让它工作。

有人可以帮忙吗?

最佳答案

在 nuxt.config.js 文件中使用这个配置对我有用

auth: {
      strategies: {
        local: {
          user: {
            property: ''
          },
          //other configs
        }
      }
      //other configs
    }

关于javascript - nuxt 认证模块 "User Data response does not contain field XXX",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66505570/

相关文章:

javascript - 如何将遗留 js 文件与 webpack 捆绑在一起?

vue.js - Nuxt 不会在路由更改时更新

Javascript代码执行顺序

javascript - 如何在 vuejs 中使用 axios 从数组发送多个请求?

vue.js - 在 Nuxt.js 中仅构建特定页面

nuxtjs3 - 将 nuxt 3 与 nuxt auth 模块一起使用时出现错误

javascript - 浏览器刷新后 Nuxt auth 用户重置

JavaScript:是否可以预加载外部站点?

vue.js - 在 nuxt.js 组件文件中拆分模板、脚本和样式(HTML、JS 和 CSS)