Support the ongoing development of Laravel.io →
Authentication Session Database

[ASK : Multitenant with Multidatabase Auth Problem]

fyi:

i'm using redis as session management and with basic setting like this :

'default' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
 ],

here's the step i created a new account with new sub domain and let's say my main domain is "example.com" :

  1. register by creating new user and new domain inside main table record lets say "cool".
  2. then i'm creating new database called "cool.example.com"
  3. running artisan for new database
  4. copy user inside main to new database

here's the real problem is : whenever i'm authenticating that new user in new subdomain -> "cool.example.com", the query match the user but instead it login as the first record inside main table.

table user main record 1 : admin table user cool.example.com : cool

in short, i'm login inside cool.example.com with username "cool" instead it's login as "admin" record.

what's the mistake here that i made ? oh yeah one more thing, i created a middleware to check current domain, if match then i add inside config with new database.connection and then use that connection to do every query

Last updated 2 years ago.
0

doh, it turns out i just need to move my custom middleware for tenant to the top

0

Sign in to participate in this thread!

Eventy

Your banner here too?

endrureza endrureza Joined 7 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.