简体   繁体   中英

Nuxt-auth ..login network header gives me strange path seems like my locale route for login page

Iam trying to use nuxt-auth module with axios and it gives me "Cannot read property 'data' of undefined"...and login headers gives strange path "Request URL: http://aqar.abdullah.link/api/api/auth/login ",any help please???

Nuxt.config.js

axios: {
baseURL:'http://aqar.abdullah.link/api',

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

}

Login Method:

 methods:{
 async Login(){
   try{
     await this.$auth.loginWith('local', {
        data:{
            email: this.email,
            password: this.password
        }
    })

    this.$router.push('/')

   }catch(e){
     this.error = e.response.data
   }

 },
},

Api response on postman:

login page path in folders

I'm not sure, I used the exact same configurations and it worked for me. But your nuxt.config.js file has a missing closing }, for the axios object.

it should look like this:

  axios: {
    baseURL: "http://aqar.abdullah.link/api"
  },
  auth: {
    strategies: {
      local: {
        endpoints: {
          login: {
            url: "/office/login",
            method: "post",
            propertyName: "data.token"
          },
          user: { url: "/auth/me", method: "post", propertyName: false },
          logout: false
        }
      }
    }
  },

also make sure you have these modules in you nuxt.config.js as well:

  modules: [
    "@nuxt/http",
    "@nuxtjs/auth",
    "@nuxtjs/axios",
  ],

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