GithubHelp home page GithubHelp logo

Comments (7)

masterix21 avatar masterix21 commented on June 27, 2024 4

Skip the finder and add two listeners for these events:

  • Illuminate\Auth\Events\Login
  • Illuminate\Auth\Events\Logout

When the login event will be fired, do your $tenant->makeCurrent(), and when the logout event will be fired, do your $tenant->forgot().

I think it’s better for you, try and give me feedback.

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024 1

If you call request()->auth() before the StartSession middleware, you'll get null always. I can suggest using another approach: instead of work with a Finder, write a middleware (in web, after StartSession) to find your tenant. It will work.

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024 1

@dambridge, the package works if you set a tenant "as current": it does not care if you do it from a middleware or a task.

from laravel-multitenancy.

sandulat avatar sandulat commented on June 27, 2024

@masterix21 @freekmurze If I do the $tenant->makeCurrent() in the login event listener, the tenant is being set, however, after I'm redirected, it is not being persisted and it becomes null. Is there any step that I'm missing? Or is this something on my side?

Basically I'm just trying to switch the tenant on the session level, not domain level.

I'm not sure if this package persists the tenant in the session. If not, I've tried to manually store the tenant id in the session, when the MadeTenantCurrentEvent is fired. However, the session is not being set in the TenantFinder and I can't read the id.

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

Last but not least, add a listener to Illuminate\Auth\Events\Authenticated event... it's another solution ;)

from laravel-multitenancy.

henryavila avatar henryavila commented on June 27, 2024

Just to register, the middleware approach gave me the needed flexibility. Worked perfectly.
I set the tenant before the return $next($request);

from laravel-multitenancy.

dambridge avatar dambridge commented on June 27, 2024

Sorry for the necro bump, just curious to see what you ended up doing. I too want to abandon the whole subdomain thing and ultimately be able to attach users to multiple tenants.

Question: if we just check for a tenant id in middleware, are we not losing some part of the identification pipeline this package needs?

from laravel-multitenancy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.