Setting team_id in session when authenticating
Hi all, filament newbie here. I'm looking into using filament for a new project, using Spatie laravel-permission via the "Spatie Roles Permissions" filament plugin. I'm still figuring it out and whether it's a good fit for what I need (I think it will be). But I'm hitting some (basic) walls.
As per the following:
https://spatie.be/docs/laravel-permission/v6/basic-usage/teams-permissions#content-working-with-teams-permissions
"After implementing a solution for selecting a team on the authentication process (for example, setting the team_id of the currently selected team on the session: session(['team_id' => $team->team_id]); )"
Firstly: where do I set the team_id in session exactly? I'm unsure as to how I hook into the authentication process.
Thanks in advance!
Teams permissions | laravel-permission
laravel-permission
8 Replies
I placed a current_team_id on the user table, then on a custom middleware we can do
On a tenant check I would do:
ensuring the tenant id is always up to date
I was reluctant to changing any models, but that makes total sense. Thanks, I'll give it a go
No problem, current means they can go to that tenant on login too.
To clarify, switchTeam is available on the user model because it implements HasTenants?
Apologies, I'm still figuring it all out
No sorry switchTeam is a custom function from jetstream/teams.
But the basis is there
Ah right, I'm not using JetStream
That's fine, it's just basically saying to update the current users team so: $user->update(['current_team_id' => Filament::getTenant()->id])
Thought so, thanks