API Authentication

Posted 2 years ago by ZetecVan

I have an API which I need to work for non-authenticated users, but if the user is authenticated, to return extra information.

I am using Laravel 5.4, Spark, and have installed Fractal for transformers.

My API routes are

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

    Route::get('/categories/{categorySlug}/{subcategorySlug?}', 'API\[email protected]'); // Gets file

});

So for a logged in user this returns the right results. For a non-logged in user I get "Unauthenticated".

I can't put the Route::get outside the Route::group closure as it doesn't run the auth to get the user.

Is the solution to create some new middleware to replace the auth?

Please sign in or create an account to participate in this conversation.