Alun

Passport raising an exception when createToken is called

Posted 7 months ago by Alun

Hi,

I've come to the situation in where I need both, a traditional login and an API login, so I decided to have a look to Laravel Passport. I had already the Laravel's Auth installed in my app, but to test the two of them coexisting I created a fresh project. First I installed the traditional login, and after I went for the Passport's. The idea was to generate a token when a user logs in, so I went with this code:

// HomeController.php
// Having the user logged in already:
public function index(){
    $user = Auth::user();
    $token = $user->createToken('Test token')->accessToken;
}

The method createToken() is raising an exception "Trying to get property of non-object", I debugged the process, and have found that, in the Eloquent's Builder, the where() method is getting passed "client-id" as second parameter, I'm not really sure, but the parameter's name is "$operator". "client-id" is what I defined in my AuthServiceProvider like so:

public function boot(){
    $this->registerPolicies();

    Passport::routes();
    Passport::personalAccessClientId('client-id');
}

I ran the install command right after installing the package and ran the migrations:

php artisan passport:install

Can it be considered a bug in the package because it's sending the wrong parameters, or am I doing something wrong?

Thank you

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