fix(teams): clear stale current_team_id when membership ends

Reset the user's persisted current_team_id when they are removed from
a team, when their team is deleted, or when refreshSession finds no
team left, so a dangling reference is never restored on next login.
This commit is contained in:
Aditya Tripathi
2026-09-08 14:44:39 +02:00
committed by Andras Bacsai
parent 12498b4b86
commit 2b92fb86b5
5 changed files with 56 additions and 1 deletions
+6 -1
View File
@@ -581,8 +581,13 @@ function refreshSession(?Team $team = null): void
if (! $team) {
// The user has no team left (e.g. just deleted their current team and
// belongs to no other): clear the stale session reference instead of
// dereferencing null.
// dereferencing null, and drop the persisted choice so it is not
// restored on next login.
session()->forget('currentTeam');
$user = Auth::user();
if ($user && ! is_null($user->current_team_id)) {
$user->forceFill(['current_team_id' => null])->saveQuietly();
}
return;
}