laravel/framework · error · InvalidArgumentException

Auth driver [{$config['driver']}] for guard [{$name}] is not

Error message

Auth driver [{$config['driver']}] for guard [{$name}] is not defined.

What it means

Thrown by AuthManager::resolve() when the guard config exists but its 'driver' value does not map to a create{Driver}Driver method and no custom creator was registered via Auth::extend(). Built-in drivers are 'session' and 'token'.

Source

Thrown at src/Illuminate/Auth/AuthManager.php:103

    protected function resolve($name)
    {
        $config = $this->getConfig($name);

        if (is_null($config)) {
            throw new InvalidArgumentException("Auth guard [{$name}] is not defined.");
        }

        if (isset($this->customCreators[$config['driver']])) {
            return $this->callCustomCreator($name, $config);
        }

        $driverMethod = 'create'.ucfirst($config['driver']).'Driver';

        if (method_exists($this, $driverMethod)) {
            return $this->{$driverMethod}($name, $config);
        }

        throw new InvalidArgumentException(
            "Auth driver [{$config['driver']}] for guard [{$name}] is not defined."
        );
    }

    /**
     * Call a custom driver creator.
     *
     * @param  string  $name
     * @param  array  $config
     * @return mixed
     */
    protected function callCustomCreator($name, array $config)
    {
        return $this->customCreators[$config['driver']]($this->app, $name, $config);
    }

    /**
     * Create a session based authentication guard.

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Register the custom driver with Auth::extend('yourDriver', fn (...) => ...) in a boot() method.
  2. Use a supported built-in driver ('session' or 'token') if no custom logic is needed.
  3. Ensure the package providing the driver is installed and its ServiceProvider is registered in config/app.php (or bootstrap/providers.php).
  4. Correct any typo in the driver string and run config:clear.

Example fix

// before
'guards' => [
    'api' => ['driver' => 'jwt', 'provider' => 'users'],
],
// throws: Auth driver [jwt] ... is not defined

// after - in AuthServiceProvider::boot()
Auth::extend('jwt', function ($app, $name, array $config) {
    return new JwtGuard($app['tymon.jwt'], $app['request']);
});
Defensive patterns

Strategy: validation

Validate before calling

$driver = config("auth.guards.{$guard}.driver");
$supported = in_array($driver, ['session', 'token'], true);
if (! $supported && ! Auth::getProvider(/* via extend registry */)) {
    throw new RuntimeException("Auth driver [{$driver}] is not registered.");
}

Type guard

function authDriverIsSupported(string $driver): bool
{
    return in_array($driver, ['session', 'token'], true)
        || app()->bound('auth.custom-creators') && array_key_exists($driver, app('auth.custom-creators') ?? []);
}

Try / catch

try {
    Auth::guard($name);
} catch (\InvalidArgumentException $e) {
    if (str_contains($e->getMessage(), 'is not defined.')) {
        // register the missing driver or fall back to session
    }
    throw $e;
}

Prevention

When it happens

Trigger: Setting auth.guards.api.driver to 'jwt' (or 'passport', 'sanctum') without first registering it; a typo such as 'sesssion'; referencing a driver provided by a package that was not installed or whose AuthServiceProvider boot no longer runs.

Common situations: Using a third-party guard (JWT, Sanctum stateful, custom SSO) and forgetting Auth::extend('jwt', ...) in a service provider; copying a config that references a driver from a different project.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/4df788966fde45f2.json. Report an issue: GitHub.