3

I am trying to build a simple website which will have no user management.

I am using the database driver for both cache and sessions.

I have removed all the user-related boilerplate code that Laravel came with, but I keep getting the error message in the title.

This is my config/auth.php:

return [

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

    'providers' => [
        'users' => [],
    ],

    'passwords' => [
        'users' => [],
    ],

];

Is it possible to have no user providers defined if one intends to not support users on his website?

EDIT 1: After disabling the Illuminate\Auth\AuthServiceProvider service provider, I get the following exception:

ReflectionException thrown with message "Class auth.driver does not exist"

> Stacktrace:
> #16 ReflectionException in vendor\laravel\framework\src\Illuminate\Container\Container.php:752
> #15 ReflectionClass:__construct in vendor\laravel\framework\src\Illuminate\Container\Container.php:752
> #14 Illuminate\Container\Container:build in vendor\laravel\framework\src\Illuminate\Container\Container.php:631
> #13 Illuminate\Container\Container:resolve in vendor\laravel\framework\src\Illuminate\Container\Container.php:586
> #12 Illuminate\Container\Container:make in vendor\laravel\framework\src\Illuminate\Foundation\Application.php:732
> #11 Illuminate\Foundation\Application:make in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:213
> #10 Illuminate\Session\DatabaseSessionHandler:userId in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:200
> #9 Illuminate\Session\DatabaseSessionHandler:addUserInformation in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:186
> #8 Illuminate\Session\DatabaseSessionHandler:Illuminate\Session\{closure}
> in vendor\laravel\framework\src\Illuminate\Support\helpers.php:1035
> #7 tap in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:188
> #6 Illuminate\Session\DatabaseSessionHandler:getDefaultPayload in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:125
> #5 Illuminate\Session\DatabaseSessionHandler:write in vendor\laravel\framework\src\Illuminate\Session\Store.php:128
> #4 Illuminate\Session\Store:save in vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php:87
> #3 Illuminate\Session\Middleware\StartSession:terminate in vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:218
> #2 Illuminate\Foundation\Http\Kernel:terminateMiddleware in vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:189
> #1 Illuminate\Foundation\Http\Kernel:terminate in public\index.php:60
> #0 require_once in server.php:21
1
  • I know this doesn't answer your question directly, so I didn't want to post this as an answer, but Laravel also has a micro-framework called Lumen. If you want a really stripped down version of Laravel, it may be worth checking out: lumen.laravel.com Commented Feb 6, 2020 at 23:59

3 Answers 3

3

You likely need to comment out the AuthServiceProvider in config/app.php:

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,  // COMMENT THIS OUT

If you post your whole stack trace we could confirm where this error is coming from

Sign up to request clarification or add additional context in comments.

5 Comments

You are right, this was needed. Didn't think of disabling the service provider.
Now I get another exception whenever I try to load the page: Class auth.driver does not exist. It happens only with the database driver and it must be because I removed the AuthServiceProvider
Backing up the stack trace will help identify where the code is running that is causing this error, could you post the whole stack of errors
weird. In line 199 of DatabaseSessionHandler it specifically checks if there is a bound Guard class before proceeding, which there shouldn't be if you don't run the AuthServiceProvider. I will take a look
I did see the same thing and then noticed there are Guards being registered elsewhere, I forgot where at the moment. Will post as soon as I find out again.
0

If you want to strip Auth entirely from your Larvel installation there are a couple of things you want to do.

In config/app.php remove the following:

Main auth service provider, usually the first entry.

Illuminate\Auth\AuthServiceProvider::class

Your application-specific auth service provider (around line 169).

App\Providers\AuthServiceProvider::class

You then want to go to App\Http\Kernel (app/Http/Kernel.php) and delete all middleware relating to auth.

This is normally commented out, but delete anyway (around line 34 in $middlewareGroups)

// \Illuminate\Session\Middleware\AuthenticateSession::class,

Next remove the aliases in $routeMiddleware

'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,

Next remove the entries in $middlewarePriority

\App\Http\Middleware\Authenticate::class
\Illuminate\Session\Middleware\AuthenticateSession::class

and

\Illuminate\Auth\Middleware\Authorize::class

Then finally, delete app/Http/Middleware/Authenticate.php.

Unfortunately, there's no way to completely remove the authentication library as it's so ingrained, but this will essentially disable it. As long as you don't call any auth based functionality you should be fine.

Comments

0
return [

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],


    'guards' => [
        'web' => [ //Laravel default guard name
            'driver' => 'session', 
            'provider' => 'users', // Laravel authenticate table/model name
        ],

        'admin' => [  //Our Custom guard name "admin"
            'driver' => 'session',  
            'provider' => 'admins',  // Our authenticate table/model name
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],


    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class, //Laravel guard model slug
        ],

        'admins' => [  
            'driver' => 'eloquent',  //Our custom eloquent
            'model' => App\Model\Admin\Admin::class, //Our custom guard model slug
        ],
    ],

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],

        'admins' => [  // And here also
            'provider' => 'admins',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.