archtechx / tenancy

Automatic multi-tenancy for Laravel. No code changes needed.
https://tenancyforlaravel.com
MIT License
3.68k stars 434 forks source link

Central app error with Laravel Nova (NotASubdomainException) #694

Closed WillyReyno closed 3 years ago

WillyReyno commented 3 years ago

Describe the bug

Hello, I'm not 100% sure if this is considered a bug, if not, feel free to redirect me to where I should report this!

I am trying to set Laravel Nova in both my central & tenants domain, I want the following:

I tried following the documentation and successfully installed Nova, however I'm getting a weird behavior on the central domain.

Following the documentation, I added this to my config nova.middleware :

    'middleware' => [
        InitializeTenancyByDomainOrSubdomain::class, 
        'web',
        Authenticate::class,
        DispatchServingNovaEvent::class,
        BootTools::class,
        Authorize::class,
    ],

When I hit my subdomain test.website.localhost/nova everything works fine, and I can access nova and see the tenant's users.

When I hit my central app website.localhost/nova I get a NotASubdomainException with error:

Hostname website.localhost does not include a subdomain.

Steps to reproduce

Expected behavior

I expect to reach nova from my central app and be able to see its own users & tenants.

Your setup

WillyReyno commented 3 years ago

I'm closing this issue!

The solution was to declare nova routes as Universal Routes :

Added universal to nova.php middleware list, before the InitializeTenancyByDomainOrSubdomain :

'middleware' => [
        'universal',
        InitializeTenancyByDomainOrSubdomain::class,
        'web',
        Authenticate::class,
        DispatchServingNovaEvent::class,
        BootTools::class,
        Authorize::class,
    ],

Thanks to @morloderex !

asanchez19 commented 1 year ago

Hey, I'm trying to do the same thing, the docs are very poor when it comes to install nova. I was wondering if you have any kind of guide? Right now I'm getting the ERR_TOO_MANY_REDIRECTS error on my browser when I try to access https://localhost.test/nova/login

Thanks in advance.

slimani-dev commented 1 year ago

i'm having the same problem @stancl

osaz-delyork commented 1 year ago

Hey, I'm trying to do the same thing, the docs are very poor when it comes to install nova. I was wondering if you have any kind of guide? Right now I'm getting the ERR_TOO_MANY_REDIRECTS error on my browser when I try to access https://localhost.test/nova/login

Thanks in advance.

Getting the same Error, i think this issue should be reopened

Mahdi-Sahib commented 1 year ago

Getting the same Error when trying to access In the tenant app

http://foo.localhost/nova

isaacdarcilla commented 1 year ago

Same error, getting ERR_TOO_MANY_REDIRECTS

DC-Sebastian commented 1 year ago

Unfortunately, I also get the error message ERR_TOO_MANY_REDIRECTS when I follow these instructions https://tenancyforlaravel.com/docs/v3/integrations/nova/

imorad87 commented 1 year ago

Any solutions yet? I am facing too many redirects issues when adding universal to nova.middleware and removing it results in an error "Tenant could not be identified on domain localhost" when accessing Nova from the central domain

jacklc-1 commented 1 year ago

Hi all, I found a fix, as this doesn't seem to be working. I created a new Middleware with the following code:

/**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if ($this->isSubdomain($request->getHost())) {
            return app(InitializeTenancyBySubdomain::class)->handle($request, $next);
        }

        return $next($request);
    }

    protected function isSubdomain(string $hostname): bool
    {
        return !in_array($hostname, config('tenancy.central_domains'));
    }

Then placed that inside the middleware array in nova.php, seems to work