title: Laravel 8/Fortify/Jetstream/Multitenancy: Error when configuring subdomain tenant identification: 'No database selected'
body: <p>I can't get the stancl/multitenancy package configured with with my Laravel 8/Fortify/Jetstream app. I'm using subdomain tenant identification and I'm getting the following error on all routes:</p>
  <blockquote>
  <p>SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: select * from <code>sessions</code> where <code>id</code> = BZmFIzeqXoJbwJkt6iiSwj7lD8EZH6I2hsyexUFv limit 1)
  Here are my configurations:</p>
  </blockquote>
  <p>I think it has something to do with the way Fortify works. Any help is highly appreciated!</p>
  <p>.env</p>
  <pre><code>DB_CONNECTION_CENTRAL=central
  DB_CONNECTION_TENANT=tenancy_db_connection
  SESSION_DRIVER=database
  </code></pre>
  <p>routes/tenant.php</p>
  <pre><code>Route::middleware([
      InitializeTenancyBySubdomain::class,
      PreventAccessFromCentralDomains::class,
      'auth:sanctum',
      'web',
  ])-&gt;group(function () {
  </code></pre>
  <p>config/database.php</p>
  <pre><code>'connections' =&gt; [
  
          'central' =&gt; [
              'driver' =&gt; 'mysql',
              'url' =&gt; env('DATABASE_URL'),
              'host' =&gt; env('DB_HOST', '127.0.0.1'),
              'port' =&gt; env('DB_PORT', '3306'),
              'database' =&gt; env('DB_DATABASE_CENTRAL', 'forge'),
              'username' =&gt; env('DB_USERNAME', 'forge'),
              'password' =&gt; env('DB_PASSWORD', ''),
              'unix_socket' =&gt; env('DB_SOCKET', ''),
              'charset' =&gt; 'utf8mb4',
              'collation' =&gt; 'utf8mb4_unicode_ci',
              'prefix' =&gt; '',
              'prefix_indexes' =&gt; true,
              'strict' =&gt; true,
              'engine' =&gt; null,
              'options' =&gt; extension_loaded('pdo_mysql') ? array_filter([
                  PDO::MYSQL_ATTR_SSL_CA =&gt; env('MYSQL_ATTR_SSL_CA'),
              ]) : [],
          ],
  
          'tenancy_db_connection' =&gt; [
              'driver' =&gt; 'mysql',
              'url' =&gt; env('DATABASE_URL'),
              'host' =&gt; env('DB_HOST', '127.0.0.1'),
              'port' =&gt; env('DB_PORT', '3306'),
              'database' =&gt; null,
              'username' =&gt; env('DB_USERNAME', 'forge'),
              'password' =&gt; env('DB_PASSWORD', ''),
              'unix_socket' =&gt; env('DB_SOCKET', ''),
              'charset' =&gt; 'utf8mb4',
              'collation' =&gt; 'utf8mb4_unicode_ci',
              'prefix' =&gt; '',
              'prefix_indexes' =&gt; true,
              'strict' =&gt; true,
              'engine' =&gt; null,
              'options' =&gt; extension_loaded('pdo_mysql') ? array_filter([
                  PDO::MYSQL_ATTR_SSL_CA =&gt; env('MYSQL_ATTR_SSL_CA'),
              ]) : [],
          ],
      ],
  </code></pre>
  <p>config/session.php</p>
  <pre><code>    'driver' =&gt; env('SESSION_DRIVER', 'database'),
      'connection' =&gt; env('DB_CONNECTION_TENANT', 'tenancy_db_connection'),
  </code></pre>
  <p>config/fortify.php</p>
  <pre><code>    'middleware' =&gt; [
          'web',
          \Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain::class
      ],
  </code></pre>
  <p>config/jetstream.php</p>
  <pre><code>    'middleware' =&gt; ['web'],
  </code></pre>
  <p>config/tenancy.php</p>
  <pre><code>&lt;?php
  
  declare(strict_types=1);
  
  use Stancl\Tenancy\Database\Models\Domain;
  use App\Models\Tenant;
  
  return [
      'tenant_model' =&gt; Tenant::class,
      'id_generator' =&gt; Stancl\Tenancy\UUIDGenerator::class,
      'domain_model' =&gt; Domain::class,
  
      /**
       * The list of domains hosting your central app.
       *
       * Only relevant if you're using the domain or subdomain identification middleware.
       */
      'central_domains' =&gt; [
          {{ LOCAL_VALET_DOMAIN }},
          {{ PROD_DOMAIN }}
      ],
  
      /**
       * Tenancy bootstrappers are executed when tenancy is initialized.
       * Their responsibility is making Laravel features tenant-aware.
       *
       * To configure their behavior, see the config keys below.
       */
      'bootstrappers' =&gt; [
          Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper::class,
          Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper::class,
          Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class,
          Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class,
          // Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed
      ],
  
      /**
       * Database tenancy config. Used by DatabaseTenancyBootstrapper.
       */
      'database' =&gt; [
          'central_connection' =&gt; env('DB_CONNECTION_CENTRAL', 'central'),
  
          /**
           * Connection used as a &quot;template&quot; for the tenant database connection.
           */
          'template_tenant_connection' =&gt; env('DB_CONNECTION_TENANT', 'tenancy_db_connection'),
  
          /**
           * Tenant database names are created like this:
           * prefix + tenant_id + suffix.
           */
          'prefix' =&gt; 'tenant',
          'suffix' =&gt; '',
  
          /**
           * TenantDatabaseManagers are classes that handle the creation &amp; deletion of tenant databases.
           */
          'managers' =&gt; [
              'sqlite' =&gt; Stancl\Tenancy\TenantDatabaseManagers\SQLiteDatabaseManager::class,
              'mysql' =&gt; Stancl\Tenancy\TenantDatabaseManagers\MySQLDatabaseManager::class,
              'pgsql' =&gt; Stancl\Tenancy\TenantDatabaseManagers\PostgreSQLDatabaseManager::class,
  
              /**
               * Use this database manager for MySQL to have a DB user created for each tenant database.
               * You can customize the grants given to these users by changing the $grants property.
               */
              // 'mysql' =&gt; Stancl\Tenancy\TenantDatabaseManagers\PermissionControlledMySQLDatabaseManager::class,
  
              /**
               * Disable the pgsql manager above, and enable the one below if you
               * want to separate tenant DBs by schemas rather than databases.
               */
              // 'pgsql' =&gt; Stancl\Tenancy\TenantDatabaseManagers\PostgreSQLSchemaManager::class, // Separate by schema instead of database
          ],
      ],
  
      /**
       * Cache tenancy config. Used by CacheTenancyBootstrapper.
       *
       * This works for all Cache facade calls, cache() helper
       * calls and direct calls to injected cache stores.
       *
       * Each key in cache will have a tag applied on it. This tag is used to
       * scope the cache both when writing to it and when reading from it.
       *
       * You can clear cache selectively by specifying the tag.
       */
      'cache' =&gt; [
          'tag_base' =&gt; 'tenant', // This tag_base, followed by the tenant_id, will form a tag that will be applied on each cache call.
      ],
  
      /**
       * Filesystem tenancy config. Used by FilesystemTenancyBootstrapper.
       * https://tenancyforlaravel.com/docs/v3/tenancy-bootstrappers/#filesystem-tenancy-boostrapper.
       */
      'filesystem' =&gt; [
          /**
           * Each disk listed in the 'disks' array will be suffixed by the suffix_base, followed by the tenant_id.
           */
          'suffix_base' =&gt; 'tenant',
          'disks' =&gt; [
              'local',
              'public',
              // 's3',
          ],
  
          /**
           * Use this for local disks.
           *
           * See https://tenancyforlaravel.com/docs/v3/tenancy-bootstrappers/#filesystem-tenancy-boostrapper
           */
          'root_override' =&gt; [
              // Disks whose roots should be overriden after storage_path() is suffixed.
              'local' =&gt; '%storage_path%/app/',
              'public' =&gt; '%storage_path%/app/public/',
          ],
  
          /**
           * Should storage_path() be suffixed.
           *
           * Note: Disabling this will likely break local disk tenancy. Only disable this if you're using an external file storage service like S3.
           *
           * For the vast majority of applications, this feature should be enabled. But in some
           * edge cases, it can cause issues (like using Passport with Vapor - see #196), so
           * you may want to disable this if you are experiencing these edge case issues.
           */
          'suffix_storage_path' =&gt; true,
  
          /**
           * By default, asset() calls are made multi-tenant too. You can use global_asset() and mix()
           * for global, non-tenant-specific assets. However, you might have some issues when using
           * packages that use asset() calls inside the tenant app. To avoid such issues, you can
           * disable asset() helper tenancy and explicitly use tenant_asset() calls in places
           * where you want to use tenant-specific assets (product images, avatars, etc).
           */
          'asset_helper_tenancy' =&gt; true,
      ],
  
      /**
       * Redis tenancy config. Used by RedisTenancyBoostrapper.
       *
       * Note: You need phpredis to use Redis tenancy.
       *
       * Note: You don't need to use this if you're using Redis only for cache.
       * Redis tenancy is only relevant if you're making direct Redis calls,
       * either using the Redis facade or by injecting it as a dependency.
       */
      'redis' =&gt; [
          'prefix_base' =&gt; 'tenant', // Each key in Redis will be prepended by this prefix_base, followed by the tenant id.
          'prefixed_connections' =&gt; [ // Redis connections whose keys are prefixed, to separate one tenant's keys from another.
              // 'default',
          ],
      ],
  
      /**
       * Features are classes that provide additional functionality
       * not needed for tenancy to be bootstrapped. They are run
       * regardless of whether tenancy has been initialized.
       *
       * See the documentation page for each class to
       * understand which ones you want to enable.
       */
      'features' =&gt; [
          // Stancl\Tenancy\Features\UserImpersonation::class,
          // Stancl\Tenancy\Features\TelescopeTags::class,
           Stancl\Tenancy\Features\UniversalRoutes::class,
          // Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
          // Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
      ],
  
      /**
       * Parameters used by the tenants:migrate command.
       */
      'migration_parameters' =&gt; [
          '--force' =&gt; true, // This needs to be true to run migrations in production.
          '--path' =&gt; [database_path('migrations/tenant')],
          '--realpath' =&gt; true,
      ],
  
      /**
       * Parameters used by the tenants:seed command.
       */
      'seeder_parameters' =&gt; [
          '--class' =&gt; 'DatabaseSeeder', // root seeder class
          // '--force' =&gt; true,
      ],
  ];
  
  </code></pre>