0
votes

Please check below code,I had written in api.php page inside routes folder in laravel 5.6 when I run this route it does not return me auth user id in the controller and it redirect me to home page.I had created login through php artisan make:auth

Route::group(['prefix'=>'User','middleware' => 'auth:api'],function(){
      //below route will display all user record from database
      Route::get('get','UsersController@getUsers'); 
 });
1

1 Answers

0
votes

In order to use API authentication you need to install and configure Laravel Passport which uses OAuth to authenticate all clients with a bearer token.

Check this page in the docs: https://laravel.com/docs/5.6/passport

EDIT: Note that you cannot test these routes in a web browser, and you should use tools like Postman.