简体   繁体   中英

Nuxt Auth Two Local Endpoints

I would like to make two local endpoints as following:

strategies: {
  localOne: {
    endpoints: {
      login: { url: "token/", method: "post", propertyName: "access" },
      user: { url: "user/me/", method: "get", propertyName: false },
      logout: false,
    }
  },
  localTwo: {
    endpoints: {
      login: { url: "user/token/", method: "post", propertyName: "access" },
      user: { url: "user/me/", method: "get", propertyName: false },
      logout: false,
    }
  }
},

But I am having the following issue in the console

client.js?06a0:77 TypeError: Cannot read property 'mounted' of undefined
at Auth.mounted (auth.js?facc:112)
at Auth.setStrategy (auth.js?facc:108)
at Auth.loginWith (auth.js?facc:123)
at _callee3$ (log-in.vue?f35c:175)
at tryCatch (runtime.js?96cf:45)
at Generator.invoke [as _invoke] (runtime.js?96cf:271)
at Generator.prototype.<computed> [as next] (runtime.js?96cf:97)
at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
at _next (asyncToGenerator.js?1da1:25)
at eval (asyncToGenerator.js?1da1:32)

How can I make two endpoints for two different auth in nuxt js? Thank you in advance

I have come up with different decision to make it work. Finally it works,

 this.$axios.post('user/token/', {
              id : res.data.id,
              firstname: res.data.firstname,
              lastname : res.data.lastname,
              email: res.data.email
          })
          .then((resp) => {
            this.$auth.setToken('local', 'Bearer ' + resp.data.access)
            this.$axios.setHeader('Authorization', 'Bearer ' + resp.data.access)
            this.$auth.ctx.app.$axios.setHeader('Authorization', 'Bearer ' + resp.data.access)
          })
          .then(() => {
            this.$axios.get('user/me/')
            .then((resp) => { 
              this.$auth.setUser(resp.data); 
              this.$router.push('/') 
            })
          .catch(() => {
          console.log(err)
          })

let me explain in simple words. Instead of using nuxt auth local, I used its methods to reach the same result as local auth login. First I am posting the data to server to create a user then loggin in with its data. Simple and Clear. I can explain it more deeper if someone needs it.

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