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

eggplantSword's avatar

Take login web routes and convert to api

My routes are in web.php but I need to install passport and use api but I don't know how to take the default laravel login logic and turn it in to api and use the api tokens for logging in, I read the docs and have done the basic setup and also added a column api_token to my users table.

This is what I have in my web.php

Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login')->name('login.attempt')->uses('Auth\LoginController@login');

Route::group(['middleware' => 'auth'], function () {
    Route::resource('/', 'DashController');
    Route::get('/logout')->name('logout')->uses('Auth\LoginController@logout');

    Route::resource('users', 'UserController');

});

If I need to later on create an app for this project should I just move everything to the api or what should I do in order to get this already started project working with passport and a future app?

0 likes
4 replies
bugsysha's avatar

Use Laravel Airlock (at least that is what it's called at the moment) for that.

Sinnbeck's avatar

Airlock is alot simpler

Also

You can use Airlock instead of passport if your application doesn't need the Client Credential grant to allow machine-to-machine communication or the Authorization Code grant. These types of communication require more advanced authentication techniques that Airlock is not built to handle.

https://divinglaravel.com/authentication-and-laravel-airlock

bugsysha's avatar

It provides you a simpler way to handle auth via API. You would not have to bother with many things that you would have to think about and implement with Passport.

Please or to participate in this conversation.