Someone :) ?
Laravel & vue.js keep session
Hi,
I've got a component that looks like this:
<subscription :subscriptions="{{json_encode($subscriptions)}}"></subscription>
Now I would like to make a post request within that component. I'm doing that like this:
methods: {
unSubscribe(subscription) {
MessageService.unSubscribe(subscription)
.then(() => {
this.subscriptions = this.subscriptions.filter((item) => subscription.id != item.id );
});
}
}
unSubscribe (message) {
return axios.post('/api/message/' + message.slug + '/unsubscribe');
},
But when I dd() the authenticated user in api.php:
Route::group(['middleware' => ['auth:api']], function () {
Route::post('/message/{message}/unsubscribe', function() {
dd(Auth::user());
});
});
In my bootstrap.js I've got:
I receive null?
window.axios.defaults.headers.common = {
'X-Requested-With': 'XMLHttpRequest'
};
How should I handle this?
Yes, I understand. It's pretty annoying to get this straight. But let's try
In your "config/auth.php", in
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
In 'driver' => 'token', have you switched to 'passport'?
'api' => [
'driver' => 'passport',
'provider' => 'users',
]
From what I'm seeing, or might be this, or missing the middleware \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class in your App\Http\Kernel.php
'web' => [
// Other middleware...
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
],
See more here https://laravel.com/docs/5.3/passport#consuming-your-api-with-javascript
Please or to participate in this conversation.