1
votes

I'm using Nuxt auth-module in my project. login API returns data in this structure:

data:{
    data:{
        user:{
        bio: null
        createdAt: "2021-06-29T12:28:42.442Z"
        email: "[email protected]"
        id: 1
        image: null
        token: "token"
        updatedAt: "2021-06-29T12:28:42.447Z"
        username: "name"
        }
     }
} 

and in nuxtconfig i seted module config like this:

  auth: {
    strategies: {
      local: {
        endpoints: {
          login: { url: 'users/login', method: 'post', propertyName: 'data.user.token' },
          user: { url: 'me', method: 'get', propertyName: 'data' },
          logout: false
        }
      }
    }
  },

but token did not save in the app. any solution?

so I found a solution:

  auth: {
    strategies: {
      local: {
        token: {
          property: 'user.token', // /user endpoint API returns user object
          type: 'Token' // if your token type is not Bearer
        },
        user: {
          user: 'user'
        },
        endpoints: {
          login: { url: '/users/login', method: 'post' },
          user: { url: '/user', method: 'get' },
          logout: false
        }
      }
    }
  },
1

1 Answers

1
votes

The structure is data.data.user and not data.user, hence IMO you'll need to specify it with a configuration like this one

auth: {
  strategies: {
    local: {
      user: {
        property: 'data.user', // or maybe 'data.data.user'
        // autoFetch: true
      },
    }
  }
}

As explained in the documentation.