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:
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
Jump to solution
18 Replies
IndomieRendang
IndomieRendangOPβ€’16mo ago
Basically I want to know how to modify the login process
ι’ζœ¨
ι’ζœ¨β€’16mo ago
try $panel->login(CustonPage:class)
IndomieRendang
IndomieRendangOPβ€’16mo ago
Thanks
Saifallak
Saifallakβ€’16mo ago
toeknee
toekneeβ€’16mo ago
Essentially you just need the tenant on the users profile i.e. current_tenant_id which is updated on switch
IndomieRendang
IndomieRendangOPβ€’16mo ago
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
toeknee
toekneeβ€’16mo ago
That sounds right, but I was saying you would need to add it in if that's a desireable feature for you.
IndomieRendang
IndomieRendangOPβ€’16mo ago
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.
toeknee
toekneeβ€’16mo ago
Yep like jetstream, it wouldn't be hard? On tenant change update user, should be fairly simple.
IndomieRendang
IndomieRendangOPβ€’16mo ago
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
toeknee
toekneeβ€’16mo ago
Ok
IndomieRendang
IndomieRendangOPβ€’16mo ago
I think, I need to only update the db if the value is different from current tenant... gotcha
toeknee
toekneeβ€’16mo ago
Which as you are hooking into the onchange tenant it will be... it will only happen when they change tenants
IndomieRendang
IndomieRendangOPβ€’16mo ago
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
IndomieRendang
IndomieRendangβ€’16mo ago
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
IndomieRendang
IndomieRendangOPβ€’16mo ago
my bad for such simple thing
toeknee
toekneeβ€’16mo ago
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
IndomieRendang
IndomieRendangOPβ€’16mo ago
Alright... thank you so much
Want results from more Discord servers?
Add your server