简体   繁体   English

nuxt auth-module “用户数据响应不包含字段 XXX”

[英]nuxt auth-module “User Data response does not contain field XXX”

I'm trying to use nuxt-auth module, my settings for this module is我正在尝试使用 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
      }
    }
  }

My "fetchactive" API returns a JSON containing a property "userDetail" which is a string containing the email address, (I also tried to make userDetail an object but with no luck). My "fetchactive" API returns a JSON containing a property "userDetail" which is a string containing the email address, (I also tried to make userDetail an object but with no luck).

eg例如


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

Nuxt auth keeps telling me that "User Data response does not contain field userDetail". Nuxt auth 不断告诉我“用户数据响应不包含字段 userDetail”。

I also tried to set "property" to false, but Nuxt auth in that cases looks for a field named "false"... I just can't get it to work.我还尝试将“property”设置为false,但在这种情况下,Nuxt auth 会寻找一个名为“false”的字段......我就是无法让它工作。

Anyone can help?任何人都可以帮忙吗?

It's happened due to the fact that auth.user endpoint search for 'data' object by default in the response but I does not exist there, as You have Your own response object key, not contained in 'data:{...}这是因为 auth.user 端点默认在响应中搜索“数据”object 但我不存在,因为您有自己的响应 object 密钥,不包含在“数据:{...}

try to add propertyName as in example in auth.user尝试添加 propertyName,如 auth.user 中的示例

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

using this configuration in the nuxt.config.js file worked for me在 nuxt.config.js 文件中使用此配置对我有用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM