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

cdrew83942's avatar

Laravel 8 | Socialite: Session Not Generated When Using 'database' driver

Context:

  • Laravel 8 | PHP 8.0 | laravel/socialite "^5.5" | socialiteproviders/manager "^4.1"
  • Running on Laravel Forge
  • I'm using Laravel Socialite with a custom Socialite Provider to authorize users via oauth 2.0 and authenticate them in Laravel.
  • When using the file session driver, a session is generated in the filesystem, and state is persisted.
  • Example session when using file driver: (I did no configuration. This worked out of the box.)
a:3:{s:6:"_token";s:40:"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";s:6:"_flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}s:50:"login_web_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";i:1;}

Issue:

  • When I change the Laravel Session driver to database, a session does not appear to be generated in the sessions table in the databse, so therefore I assume the session state is not persisted.
  • An exception is thrown after the oauth server redirects to my oauth/callback route:
Laravel\Socialite\Two\InvalidStateException

if ($this->hasInvalidState()) {

            throw new InvalidStateException();

        }

What I've tried

  • I've tried running the default php artisan session:table which creates this snippet in migrations, and I added a state column.
         Schema::create('sessions', function (Blueprint $table) {
            $table->string('id')->primary();
            $table->foreignId('user_id')->nullable()->index();
            $table->string('ip_address', 45)->nullable();
            $table->string('state')->nullable();
            $table->text('user_agent')->nullable();
            $table->text('payload');
            $table->integer('last_activity')->index();
        });

Any help is appreciated!

0 likes
1 reply
sr57's avatar

@cdrew83942

Have you cleared the cache?

php artisan cache:clear
php artisan config:clear

Please or to participate in this conversation.