jeudi 26 janvier 2017

Vue.js 2, Laravel 5.4, Passport, axios - API 'GET' Problems

I'm tying to get an API working with Vue.JS 2 and Laravel 5.4. In my App.vue I have the following code:

export default {
  name: 'app',
  components: {
    Hello
  },
  created () {
    const postData = {
      grant_type: 'password',
      client_id: 2,
      client_secret: 'somesecret',
      username: 'my@mail.com',
      password: 'password',
      scope: ''
      }
      this.$http.post('http://localhost:8000/oauth/token', postData)
        .then(response => {
           console.log(response)
           const header = {
             'Accept': 'application/json',
             'Authorization': 'Bearer ' + response.body.access_token
           }
           this.$http.get('http://localhost:8000/api/test', {headers: header})
             .then(response => {
               console.log(response)
             })
        })
   }
}

While 'POST' is working without any problems, I just can't get 'GET' working.

My console.log shows the following:

Uncaught (in promise) TypeError: Cannot read property 'access_token' 
of undefined at eval (eval at <anonymous> (app.js:810), <anonymous>:33:51)
(anonymous) @ App.vue?86c0:29

Unfortunately I couldn't find any explanation why this might be happening. Does anybody know if they changed 'access_token' to something else or why this is happening?

Hope someone knows :|

Thanks in advance!

Paul



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire