fix(team): resolve stored team on deletion and impersonation

Use resolveStoredTeam() instead of teams()->first() when picking the
next active team after a team deletion or when an admin switches into
a user's account, so a valid stored preference wins over an arbitrary
first team. DeleteTeam now returns null when the deletion leaves the
owner with multiple teams, deferring to the selection screen instead
of guessing. refreshSession also stops persisting current_team_id
while impersonating, so viewing another user's account no longer
overwrites their real last-active team.
This commit is contained in:
Aditya Tripathi
2026-09-08 14:44:42 +02:00
committed by Andras Bacsai
parent f511921895
commit e52390ec03
4 changed files with 60 additions and 5 deletions
+4 -2
View File
@@ -602,9 +602,11 @@ function refreshSession(?Team $team = null): void
});
session(['currentTeam' => $team]);
// Persist the active team so it can be restored after logout/login.
// Persist the active team so it can be restored after logout/login — but
// never while an admin is impersonating, so viewing another user's account
// does not overwrite that user's real last-active team.
$user = Auth::user();
if ($user && $user->current_team_id !== $team->id) {
if ($user && ! session('impersonating') && $user->current_team_id !== $team->id) {
$user->current_team_id = $team->id;
$user->saveQuietly();
}