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

nuxt auth-module "User Data response does not contain field XXX"

我正在尝试使用 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 returns 一个 JSON 包含一个 属性 “userDetail”,它是一个包含电子邮件地址的字符串,(我也尝试制作userDetail 一个对象但没有运气)。

例如


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

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

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

有人可以帮忙吗?

发生这种情况是因为 auth.user 端点默认在响应中搜索 'data' 对象,但我在那里不存在,因为你有自己的响应对象键,不包含在'数据:{...}

尝试添加 propertyName,如 auth.user

中的示例
endpoints: {
      user: { url: 'http://localhost:8085/api/user/fetchactive', method: 'get', propertyName: '' }
    }
  }

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

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