i want to use web authentication for all api routes. I created middleware and this is how it looks like
Route::group(['middleware' => ['auth:web'], 'prefix' => 'v1',], function ($router) {
Route::apiResource('subscriptions', 'Api\SubscriptionController');
Route::post('subscriptions/{id}/resend', 'Api\SubscriptionController@resend')->name('resend');
Route::post('subscriptions/{id}/grace', 'Api\SubscriptionController@addGrace')->name('grace');
Route::apiResource('accounts', 'Api\SocialMediaAccountController');
Route::post('accounts/{id}/reset', 'Api\SocialMediaAccountController@reset');
Route::apiResource('customers', 'Api\CustomerController');
});
When i am already logged in and i try to make request to api route, it redirect me to the home page. How can i fix this ?
Here is the config/auth.php
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
I don't want api routes to be redirected if i am already logged in. I just want to do web authorization and continue with same request.
I don't want api routes to be redirected. I just want to do web authorization and continue with same request.
If you aren't authenticated then how do you want this to work?auth:web
middleware.auth:api
middleware for protected api routes?