Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

unkown.persone's avatar

Use the authenticated user of the session in laravel API

I have a session login system for a few guards. I'm using Vue a lot and I came to the point where I need authentication in Vue in order to fetch and post data properly. The question is how could I get the authenticated session user to work with API. So in api.php I want to use a controller whose Middleware the authenticated user. I don't want to use Passport because I only have logins over the webpage and not API.

0 likes
2 replies
beso94's avatar

In your routes/api.php, you should change Route::middleware('auth:api') to Route::middleware('auth'), so it will use default (probably 'web') guard for authentication instead of 'api' guard

Please or to participate in this conversation.