lavina
1 month ago
204
4
Laravel

Unable to confirm Auth::user

Posted 1 month ago by lavina

Hello, I am implementing the passport auth in an existing application.

I ran : composer require laravel/passport php artisan migrate php artisan passport:install

Added: use HasApiTokens; to User model

Updated AuthServiceProvider with: public function boot() { $this->registerPolicies();

    Passport::routes();
}

And then updated config/auth return [ ....

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],

....

] My route is: Route::group(['middleware' => 'auth:api'], function(){ Route::get('/products', 'Api\[email protected]'); });

class CrudController extends Controller { public function allProductsList() { $id=Auth::id(); dd($id); return (Product::all()); } }

I access the link with bearer token in header And the return id is always empty, what am i missing??

Please sign in or create an account to participate in this conversation.