[Vuejs]-Laravel_token is valid for first request but not subsequent requests

0๐Ÿ‘

โœ…

I solved this by removing the web middleware from my API route. Why it was there in the first place, I have no idea.

I changed my api.php from

Route::group([
    'middleware' => [
        'web',
        'auth:api']], function() {

    Route::post('/banking/transactions', 'TransactionController@store');

    Route::get('/banking/accounts', 'BankAccountDirectoryController@index');
    Route::get('/accounts/{account}', 'BankAccountDirectoryController@show');
    Route::get('/banking/accounts/search/{term?}', 'BankAccountDirectoryController@search');
});

to

Route::group([
    'middleware' => [
        'auth:api']], function() {

    Route::post('/banking/transactions', 'TransactionController@store');

    Route::get('/banking/accounts', 'BankAccountDirectoryController@index');
    Route::get('/accounts/{account}', 'BankAccountDirectoryController@show');
    Route::get('/banking/accounts/search/{term?}', 'BankAccountDirectoryController@search');
});

Should the API routes be under the web group to benefit from the middleware, or is it purely for UI? Am I safe to do this?

Leave a comment