5
votes

I'm trying to set up my custom API with Passport (well, I'm already halfway through, just need to build my authentication). Whenever I'm trying to create a personal access token from my Passport dashboard (/home route), I get a 'Whoops, something went wrong!' error.

This comes from my Vue component (PersonalAccessTokens.vue), and my console logs me a 500 internal server error at the Post route for storing personal access tokens...

\Laravel\Passport\Http\Controllers\PersonalAccessTokenController@store is the method responsible but I can't seem to find something outof the ordinary as I did exactly follow the Laracasts video about Passport

Anyone else experiencing this problem ?

TIA!

2
What's the error in the error log...?Farkie
Nothing, the error comes from my Vue component I guess, it should be in the /logs directory right? Assuming the server returns a 500 it should be logged somewhere..Fabian Tjoe A On
@FabianTjoeAOn if you're using chrome open developer console, go to network tab, then perform request. You should see request you've just performed. Click on it, then select preview from this request's tab. This, or just look at storage/log/laravel.log and see stack trace :)Skysplit
Oh wow thanks, my logs are empty but didn't know that you could use the network tab like this. It says "ErrorException in ClientRepository.php line 66: Trying to get property of non-object". Which refers to the function personalAccessClient(): public function personalAccessClient() { if (Passport::$personalAccessClient) { return Client::find(Passport::$personalAccessClient); } else { return PersonalAccessClient::orderBy('id', 'desc')->first()->client; } }Fabian Tjoe A On

2 Answers

12
votes

I figured it out.

Apparently it can't read my personal access token client, that you should generate when setting up Passport by using the command: php artisan passport:install

Running this command solves my problem.

Reference: https://laracasts.com/discuss/channels/laravel/create-personal-access-token-in-laravel-passport-is-failing

3
votes

A little more info on this as I've been having the same problem. You need to run:

php artisan passport:install

each time you refresh your migrations by doing:

php artisan migrate:refresh

To deal with this I've just added a script to package.json which uses npm-run-all so I can do it in one command:

"scripts": {
  // Other scripts
  "migrate:refresh": "php artisan migrate:refresh",
  "passport:install": "php artisan passport:install",
  "db:refresh": "npm-run-all --sequential migrate:refresh passport:install"
}

Now I can just do:

npm run db:refresh