php - Laravel/Passport - After remigration keys are not usable

Solution:

Even though this question is quite old. But we can use Event Listeners to achieve repeated steps.

Under app\Providers\EventServiceProvider.php add the following code in boot() method.

Laravel 9

public function boot()
{
    parent::boot();

    Event::listen(CommandFinished::class, function(CommandFinished $event) {
        if($event->command === 'migrate:fresh') {
            Artisan::call('passport:install', [ '--force' => true]);
            echo Artisan::output();
        }
    });
}

I found the Illuminate\Database\Events\MigrationsEnded not working for my case. But other one, Illuminate\Console\Events\CommandFinished trigger on all command executions.

Answer

Solution:

Do this to overwrite the existing keys and it will work

php artisan passport:install --force

Or you may publish Passport's configuration file using

php artisan vendor:publish --tag=passport-config

which will then provide the option to load the encryption keys from your environment variables:

Refer this for detailed instruction https://laravel.com/docs/7.x/passport

Source