419 error on login ONLY when session driver is "database"

After reading through the other posts involving 419 errors on Filament, I have not been able to resolve this issue. When setting the session driver to database, I get a 419 error on logging in, but if I change it to file instead of database it works perfectly fine. A few things: my users table uses uuids instead of an int, but I have updated the session table migration accordingly, migrated to a completely fresh database, and verified that the database connection works by using tinker to insert a new user into the database. My migration:
public function up(): void
{
/* ... */
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('tenant_id')->nullable()->references('id')->on('tenants')->cascadeOnDelete();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});

Schema::create('sessions', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('user_id')->references('id')->on('users')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
/* ... */
}
public function up(): void
{
/* ... */
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('tenant_id')->nullable()->references('id')->on('tenants')->cascadeOnDelete();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});

Schema::create('sessions', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('user_id')->references('id')->on('users')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
/* ... */
}
my .env:
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=atlas
DB_USERNAME=root
DB_PASSWORD=

SESSION_DRIVER=database
#SESSION_SECURE_COOKIE=true
#SESSION_COOKIE="atlas_session"
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=atlas
DB_USERNAME=root
DB_PASSWORD=

SESSION_DRIVER=database
#SESSION_SECURE_COOKIE=true
#SESSION_COOKIE="atlas_session"
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
I have no idea why changing the session driver to database impacts it like this, but it's only when the driver is database, if I change it to file it works
Solution:
sorry for the delay, I was working with a colleague on this, and we discovered that the session migration had the 'id' column set to 'uuid' instead of 'string' and that was throwing off everything, preventing the session from being stored properly, and then couldn't be retreived either.
Jump to solution
2 Replies
Dennis Koch
Dennis Koch3w ago
Sounds like Laravel has issues setting the session 🤔 Can you check whether this simple test works via 2 requests?
session()->set('test', 'test');
session()->set('test', 'test');
and
dd(session('test'));
dd(session('test'));
Solution
Carrot
Carrot3w ago
sorry for the delay, I was working with a colleague on this, and we discovered that the session migration had the 'id' column set to 'uuid' instead of 'string' and that was throwing off everything, preventing the session from being stored properly, and then couldn't be retreived either.

Did you find this page helpful?