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

admin2025-04-21  0

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?

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?

Share Improve this question asked Mar 6, 2021 at 12:20 sangio90sangio90 1791 gold badge3 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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

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

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: '' }
    }
  }
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745235195a291686.html

最新回复(0)