DEV Community

Discussion on: User Authentication using Laravel's passport

Collapse
 
kabircse profile image
Kabir Hossain

I am trying to implement laravel passport on laravel 6. But I am getting an error.
Login and registration are ok. But I am getting an error when trying to fetch(authentic) pages.

The error is here pastebin.com/1M4iC3u5

My api.php



Route::group(['prefix'=>'v1'],function(){
        Route::post('register', 'API\Auth\RegisterController@register');
        Route::post('login', 'API\Auth\RegisterController@login');
        Route::get('gas_stations', 'API\GasStationController@index');
        //it works
        //Route::get('brands', 'API\BrandController@index');


        Route::group(['middleware'=>['auth:api']],function() {
            //it is not working
            Route::get('brands', 'API\BrandController@index');
        });    
    });
Collapse
 
malwarebo profile image
Irfan

I don't know how you have set up the flow but here is something that should probably work.

Inside the BrandController add this to the constructor.

$this->middleware(['auth'']);

Next, the index function inside the controller should look like this:

public function index()
    {
        $brands = Brands::all();
        return view('brands.index');
    }

Then use the Route directly as:

Route:get(/brands, BrandController@index);
Collapse
 
kabircse profile image
Kabir Hossain

Thanks a lot