Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gandra's avatar

php artisan optimize throws Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined

I am working on laravel 5.4 app. I have custom User class and custom UserProvider.

App is working fine. But when I execute following command: composer install --no-dev --optimize-autoloader I am receiving following error:

vagrant@my-api:~/Code/my-api$ composer install --no-dev
--optimize-autoloader Loading composer repositories with package information Installing dependencies from lock file Nothing to install or update Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize PHP Fatal error:  Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined. in /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php:40 Stack trace:
#0 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(123): Illuminate\Auth\AuthManager->createUserProvider('users')
#1 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(96): Illuminate\Auth\AuthManager->createSessionDriver('web', Array)
#2 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(70): Illuminate\Auth\AuthManager->resolve('web')
#3 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(294): Illuminate\Auth\AuthManager->guard()
#4 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Illuminate\Auth\AuthManager->__call('check', Array)
#5 /home/vagrant in /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php on line 40 PHP Fatal error:  Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined. in /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php:40 Stack trace:
#0 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(123): Illuminate\Auth\AuthManager->createUserProvider('users')
#1 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(96): Illuminate\Auth\AuthManager->createSessionDriver('web', Array)
#2 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(70): Illuminate\Auth\AuthManager->resolve('web')
#3 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(294): Illuminate\Auth\AuthManager->guard()
#4 /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Illuminate\Auth\AuthManager->__call('check', Array)
#5 /home/vagrant in /home/vagrant/Code/my-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php on line 40 Script php artisan optimize handling the post-install-cmd event returned with error code 255 vagrant@my-api:~/Code/my-api$

This is my config/auth.php:

<?php
return [
    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
    ],
    'providers' => [
        'users' => [
            'driver' => 'external-user',
            'model' => \Dnc\Extensions\DncUser::class,
        ],
    ],
    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],
];

This is my app/Providers/AuthServiceProvider.php:

use Dnc\Extensions\ExternalUserUserProvider;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Auth;

class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [];

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

        Auth::provider('external-user', function ($app, array $config) {
            return new ExternalUserUserProvider();
        });
    }
}

This is my custom UserProvider:

namespace Dnc\Extensions;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider as IlluminateUserProvider;

class ExternalUserUserProvider implements IlluminateUserProvider
{
    public function retrieveById($identifier)
    {
        // ...
    }

    public function retrieveByToken($identifier, $token)
    {
        // T...
    }

    public function updateRememberToken(Authenticatable $user, $token)
    {
        // ...
    }

    public function retrieveByCredentials(array $credentials)
    {
        //. ..
    }

    public function validateCredentials(Authenticatable $user, array $credentials)
    {
        // ...
    }

}

and my custom User:

namespace Dnc\Extensions;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class DncUser extends Authenticatable implements JWTSubject
{
    // ...
}

Composer version: 1.4.1 2017-03-10 09:29:45

This is my composer.json: https://gist.github.com/gandra/0082846ab0aeb0fcf8faf2c61fd9b923#file-composer-json

The same error PHP Fatal error: Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined. I get executing only php artisan optimize

IMPORTANT INFO I have just realized that php artisan optimize is running fine after composer install but fails after composer install --no-dev

I have tried to move all packages from require-dev to require section and:

  1. composer install pass ok
  2. composer install --no-dev fails with **PHP Fatal error: Uncaught InvalidArgumentException: Authentication user provider [external-user] is not defined. in /home/vagrant/Code/kibernum-dnc-api/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserProviders.php:40** .

Is this laravel issue or composer issue?

Any idea how to fix this error?

0 likes
0 replies

Please or to participate in this conversation.