Im using Laravels default auth to lock down some paths in the routes/api.php file.
Route::get('/projects', 'ProjectController@index')->middleware('auth:api');
I log the user in via a PHP form (not via a http request via Vue). This creates the session and when I submit a HTTP request via Vue I can see that the header includes the Cookie and X-CSRF-Token however I keep getting a 401 {"error":"Unauthenticated."}
In my config/auth I have api driver set as 'token' (have tried changing this to 'session' but that did work :/)
From my understanding and what I have read online I should be able to use the default Laravel auth functionality to accomplish API calls from Vue HTTP requests.
this.$http.get('/api/projects')
.then(response => {
this.projects = response.body;
})
.catch (err => {
console.log(err);
});
I've read about methods of authenticating by generating an JWT token and storing that in local storage when the user logs in. Is this the method I should use or should I be able to accomplish it with the default Laravel Auth middleware?
Hope my questions make sense, any help/advice would be appreciated.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ktrpMJ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire