Team switching session scoping limits with Jetstream Teams
0 reputation · 15 Oct 2025, 07:39 UTC
0 reputation · 15 Oct 2025, 07:39 UTC
The objective is to understand the documented behavior and limits of Jetstream's Team Management when switching the active team in a session, specifically for an integration test without production credentials.
Jetstream provides teams with a many-to-many user-team relationship via a pivot table for role assignment, team switching logic that updates session state to scope application data, and role-based capabilities. Team logic adds complexity to queries because models are expected to be scoped to the current team ID.
There is uncertainty about where responsibility for state consistency lies after a team switch, particularly with cached data, and what limits exist for scoping and permission enforcement across teams.
Is cache invalidation on team switch expected to be handled by Jetstream or by application code? What documented limits apply to scoping Eloquent queries to the current team ID? Does the team switching mechanism guarantee session consistency across concurrent requests?
Likely explanation:
Jetstream updates the session’s current_team_id but does not automatically invalidate caches; cache clearing must be done by the application.
Eloquent scoping via the HasTeams trait applies only to models that include the trait; plain queries are not automatically limited to the current team.
Session consistency relies on the session driver’s locking; rapid concurrent team‑switch requests may temporarily expose a stale current_team_id, so permission checks should be re‑validated per request.
bootHasTeams method adds a global scope that wraps queries with where('team_id', session('current_team_id')).team_id column on the pivot table and any tables that are scoped by team.cache()->put($key, $value, now()->addMinutes(5), ['team' => session('current_team_id')])) and ensure your cache store supports tagging.session('current_team_id') reflects the intended team and that any permission checks succeed only for the correct team.Please indicate whether you are using a distributed cache driver (e.g., Redis) that supports tag‑based invalidation; this determines if cache tagging alone is sufficient or if additional clearing logic is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.