Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing Waterhole to existing project seems to break custom session driver #80

Open
jafar690 opened this issue Dec 27, 2024 · 0 comments

Comments

@jafar690
Copy link

jafar690 commented Dec 27, 2024

Bug description

I just installed Waterhole and i get the error that my custom session driver is not supported, When i remove waterhole, everything works fine

image

Steps to reproduce

Create a custom session handler class, in this case, i want to use the session table for multiple authenticable models

<?php

namespace Core\Extensions;

use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Session\DatabaseSessionHandler;

class CustomDatabaseSessionHandler extends DatabaseSessionHandler
{
    /**
     * Add the user information to the session payload.
     *
     * @param  array  $payload
     * @return $this
     *
     * @throws BindingResolutionException
     */
    protected function addUserInformation(&$payload): static
    {
        if ($this->container->bound(Guard::class)) {
            $payload['userable_type'] = $this->user() ? get_class($this->user()) : null;
            $payload['userable_id'] = $this->userId();
        }

        return $this;
    }

    /**
     * Get the currently authenticated user's ID.
     *
     *
     * @throws BindingResolutionException
     */
    protected function user(): mixed
    {
        return $this->container->make(Guard::class)->user();
    }
}

Modify sessions table to make it polymorphic

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('sessions', function (Blueprint $table) {
            $table->string('id')->primary();
            $table->string('userable_type')->nullable();
            $table->foreignId('userable_id')->nullable()->index();
            $table->string('ip_address', 45)->nullable();
            $table->text('user_agent')->nullable();
            $table->longText('payload');
            $table->integer('last_activity')->index();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sessions');
    }
};

Then finally register the custom session handler in boot method of AppServiceProvider

Session::extend('custom-database', function ($app) {
            $table = $app['config']['session.table'];
            $lifetime = $app['config']['session.lifetime'];
            $connection = $app['db']->connection($app['config']['session.connection']);

            return new CustomDatabaseSessionHandler($connection, $table, $lifetime, $app);
        });

Logs

[2024-12-27 14:04:03] local.ERROR: Driver [custom-database] not supported. {"exception":"[object] (InvalidArgumentException(code: 0): Driver [custom-database] not supported. at /testapp/vendor/laravel/framework/src/Illuminate/Support/Manager.php:109)
[stacktrace]
#0 /testapp/vendor/laravel/framework/src/Illuminate/Support/Manager.php(80): Illuminate\\Support\\Manager->createDriver('custom-database')
#1 /testapp/vendor/laravel/framework/src/Illuminate/Session/SessionServiceProvider.php(52): Illuminate\\Support\\Manager->driver()
#2 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(908): Illuminate\\Session\\SessionServiceProvider->Illuminate\\Session\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#3 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\\Container\\Container->build(Object(Closure))
#4 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(963): Illuminate\\Container\\Container->resolve('session.store', Array, true)
#5 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\\Foundation\\Application->resolve('session.store', Array)
#6 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(948): Illuminate\\Container\\Container->make('session.store', Array)
#7 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(1454): Illuminate\\Foundation\\Application->make('session.store')
#8 /testapp/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php(120): Illuminate\\Container\\Container->offsetGet('session.store')
#9 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(908): Illuminate\\Routing\\RoutingServiceProvider->Illuminate\\Routing\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#10 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\\Container\\Container->build(Object(Closure))
#11 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(963): Illuminate\\Container\\Container->resolve('redirect', Array, true)
#12 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\\Foundation\\Application->resolve('redirect', Array)
#13 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(948): Illuminate\\Container\\Container->make('redirect', Array)
#14 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(1454): Illuminate\\Foundation\\Application->make('redirect')
#15 /testapp/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php(182): Illuminate\\Container\\Container->offsetGet('redirect')
#16 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(908): Illuminate\\Routing\\RoutingServiceProvider->Illuminate\\Routing\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#17 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\\Container\\Container->build(Object(Closure))
#18 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(963): Illuminate\\Container\\Container->resolve('Illuminate\\\\Cont...', Array, true)
#19 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\\Foundation\\Application->resolve('Illuminate\\\\Cont...', Array)
#20 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(948): Illuminate\\Container\\Container->make('Illuminate\\\\Cont...', Array)
#21 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(1454): Illuminate\\Foundation\\Application->make('Illuminate\\\\Cont...')
#22 /testapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(237): Illuminate\\Container\\Container->offsetGet('Illuminate\\\\Cont...')
#23 /testapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(208): Illuminate\\Support\\Facades\\Facade::resolveFacadeInstance('Illuminate\\\\Cont...')
#24 /testapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(349): Illuminate\\Support\\Facades\\Facade::getFacadeRoot()
#25 /testapp/vendor/hotwired-laravel/turbo-laravel/src/TurboServiceProvider.php(122): Illuminate\\Support\\Facades\\Facade::__callStatic('macro', Array)
#26 /testapp/vendor/hotwired-laravel/turbo-laravel/src/TurboServiceProvider.php(38): HotwiredLaravel\\TurboLaravel\\TurboServiceProvider->configureRequestAndResponseMacros()
#27 /testapp/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): HotwiredLaravel\\TurboLaravel\\TurboServiceProvider->boot()
#28 /testapp/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#29 /testapp/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#30 /testapp/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#31 /testapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#32 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1036): Illuminate\\Container\\Container->call(Array)
#33 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1017): Illuminate\\Foundation\\Application->bootProvider(Object(HotwiredLaravel\\TurboLaravel\\TurboServiceProvider))
#34 [internal function]: Illuminate\\Foundation\\Application->Illuminate\\Foundation\\{closure}(Object(HotwiredLaravel\\TurboLaravel\\TurboServiceProvider), 20)
#35 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1016): array_walk(Array, Object(Closure))
#36 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#37 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(263): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#38 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(186): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#39 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(170): Illuminate\\Foundation\\Http\\Kernel->bootstrap()
#40 /testapp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#41 /testapp/public/index.php(51): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#42 /Users/test/.composer/vendor/laravel/valet/server.php(110): require('/Users/test/C...')
#43 {main}
"}

Environment

Application Name: ****
  Laravel Version: 10.48.25
  PHP Version: 8.3.14
  Composer Version: 2.8.3
  Environment: local
  Debug Mode: ENABLED
  URL: ****
  Maintenance Mode: OFF
  Waterhole Version: 0.4.10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant