Comments (7)
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.
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.
@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.
@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.
Last but not least, add a listener to Illuminate\Auth\Events\Authenticated
event... it's another solution ;)
from laravel-multitenancy.
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.
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)
- Queue is not working after upgrading Laravel Framework to 9.34+
- SQL error when trying to use landlord database HOT 3
- Support for custom primary key on Tenant model HOT 1
- How can I access all tenant data at once?
- Tenant Not Set (Vapor + Octane) HOT 1
- Current tenant not determined when dispatching queued closures HOT 6
- When dispatching a Tenant Aware Job in sync mode from a test, any prior/current DB transaction is cleared HOT 2
- Model ignore tenant when add Observer HOT 2
- Tenant password reset token is being stored on landlord password_reset_tokens table HOT 1
- Prefixing cache doesn't work fine with file-store HOT 3
- Conflict with Rabbitmq package from vyuldashev HOT 1
- Scheduler : Large (longer) jobs, multiple tenants, stops.
- Tenant-Aware Job Scheduling with Horizon HOT 3
- MakeQueueTenantAwareAction seems to break active requests when Queue Connection is sync HOT 4
- base table or view not found with AWS SQS queue for job TenantAware HOT 12
- randomly receive Invalid catalog name: 1046 No database selected (Connection: mysql, SQL: insert into failed_jobs (uuid, connection, queue, payload, exception, failed_at) on queue sqs HOT 5
- Tenant Aware Queue Fails No Database Selected when running from supervisor in a multi tenant environment using AWS SQS FIFO HOT 2
- Update documentation at https://spatie.be to `v3` HOT 3
- in_array(): Argument #2 ($haystack) must be of type array, null given {"exception":"[object] (TypeError(code: 0): in_array(): Argument #2 ($haystack) must be of type array, null given at /spatie/laravel-multitenancy/src/Actions/MakeQueueTenantAwareAction.php:79) HOT 1
- Cache issue with spatie/laravel-permission in TenantAware Command HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-multitenancy.