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

danyal14's avatar

Can I use Laravel Passport & session both?

Hello Guys,

I want to keep both sessions (user/password) for normal web-admin + Laravel Passport for API for SPA apps in the same Laravel application, is that possible?

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, it is possible to use Laravel Passport for API authentication and sessions for web authentication in the same Laravel application. You can use Laravel's built-in session middleware for web authentication and Passport's middleware for API authentication.

To use sessions for web authentication, you can add the web middleware group to your routes:

Route::group(['middleware' => ['web']], function () {
    // web routes here
});

To use Passport for API authentication, you can add the auth:api middleware group to your API routes:

Route::group(['middleware' => ['auth:api']], function () {
    // API routes here
});

Make sure to configure Passport properly by running the necessary migrations and setting up the necessary routes and controllers.

Also, keep in mind that using sessions for web authentication may not be suitable for SPA applications, as they typically use token-based authentication. In that case, you may want to consider using Passport for both web and API authentication.

Please or to participate in this conversation.