简体   繁体   中英

nuxt-auth setting user object after login

im using the nuxt-auth module. I've got it to work so far. I am able to login properly. But whenever i login, the user object in my store does not get set. It seems like my API is getting called without parameters so it does not know which user to set.

nuxt.config.js

auth: {
    redirect: {
      login: '/login',
      logout: '/login',
      callback: '/login',
      home: '/'
    },
    strategies: {
      local: {
        endpoints: {
          login: {
            url: 'token',
            method: 'post',
            propertyName: 'token'
          },
          user: {
            url: 'microservice/user',
            method: 'get',
            propertyName: false
          },
          logout: false
        }
      },
      watchLoggedIn: true,
      resetOnError: true
    }
  },

logging in

 await this.$auth.loginWith('local', {
          data: {
            username: this.username,
            password: this.passwort
          }
        })

example API-User

{
  "method": "GET",
  "path": "/user/102",
  "query": "",
  "response": {
    "type": "single",
    "payload": {
      "id": 102,
      "firstname": "super",
      "name": "test",
      "username": "stest1",
     //some data
    }
  }
}

After retrieving a token and setting it, my app sends a request without query/parameters to my user-API. Either im doing something wrong, or am just too dumb too see the right way to set my user. However, if i set my user-Route to for example 'microservice/user/102' it is able to retrieve that one specific user.

Hoping anyone can help! :D

I think you should set it propertyName for user endpoint

user: {
    url: 'microservice/user',
    method: 'get',
    propertyName: payload
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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