Redirect login to the last accessed tenant?
Can I set/store the last accessed tenant when logout and then it will be the next destination after login?
Solution:Jump to solution
Well, we can listen to Logout event, there we get the previous url, manipulate the string to get the last tenant url , store to user db (or whatever) and done
18 Replies
Basically I want to know how to modify the login process
try
$panel->login(CustonPage:class)
Thanks
https://filamentphp.com/docs/3.x/panels/tenancy#setting-the-default-tenant
store last accssed tenant in cache or db or anything and use this method
Essentially you just need the tenant on the users profile i.e. current_tenant_id which is updated on switch
Hi @toeknee , after some time of exploration, I think the "current" tenant is simply determined by the tenant route parameter, there's no such "switching" event there, in my understanding so far. Please correct me if I'm wrong.
Also to answer @Saifallak, since the identifier is a persistent middleware, storing it in the database will write the db too many times as a single page may call the middleware 3-4 times during load time and can even more, then live components and polling will also take part of it, which I believe will ruin the performance. I couldn't spot the good "checkpoint" when to write to the db, was thinking during logout event but it already lost the tenant instance. I will also think about cache or cookie, but I decided to forget it for a moment. Low priority π
Anyway thanks guys
That sounds right, but I was saying you would need to add it in if that's a desireable feature for you.
I assumed your suggestion told me to store the current tenant id in db, is it true? Actually I was also thinking about that, like how laravel jetstream works. But then I think the trade off doesn't worth it, I will think about that feature later.
Yep like jetstream, it wouldn't be hard? On tenant change update user, should be fairly simple.
Yes it is very simple and easy to do, only if I've already spotted the correct timing to update the db, not updating the db multiple times in a second
wait
Ok
I think, I need to only update the db if the value is different from current tenant... gotcha
Which as you are hooking into the onchange tenant it will be... it will only happen when they change tenants
Anyway, you're talking about onchange, and also switching... Is there an event dispatched on switching?
I'm not sure there is, since we can switch the tenant by changing the url in address bar π€
Nope, it will be useless for user accessing different tenants simultaneously in different tabs π
Solution
Well, we can listen to Logout event, there we get the previous url, manipulate the string to get the last tenant url , store to user db (or whatever) and done
my bad for such simple thing
Yep that's one way, make sure to check for timeouts too. And you can probabaly do that by persisiting the tenant in the sessio
Alright... thank you so much