sangio90
sangio90

Reputation: 179

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

  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).

e.g.


{"userDetail":{"email":"[email protected]"}}

Nuxt auth keeps telling me that "User Data response does not contain field 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.

Anyone can help?

Upvotes: 3

Views: 4390

Answers (2)

Jhon Lester Pineda
Jhon Lester Pineda

Reputation: 81

using this configuration in the nuxt.config.js file worked for me

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

Upvotes: 3

devzom
devzom

Reputation: 716

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:{...}

try to add propertyName as in example in auth.user

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

Upvotes: 2

Related Questions