Files
coolify/app/Livewire/SelectTeam.php
Aditya Tripathi a618e4c85e fix(teams): guard current_team_id clear against concurrent writes
Make clearStoredTeamIfMatches perform an atomic conditional UPDATE
so a concurrent team switch isn't clobbered, and call it for the
deleting owner in DeleteTeam so their stored team id doesn't point
at a deleted team. refreshSession now falls back to
resolveStoredTeam() instead of an arbitrary first team. Add a
return type to SelectTeam::render() and tests covering owner
deletion and concurrent-selection preservation.
2026-08-25 17:25:32 +00:00

51 lines
1.3 KiB
PHP

<?php
namespace App\Livewire;
use App\Models\Team;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class SelectTeam extends Component
{
// mount()/selectTeam() intentionally have no return type: Livewire's
// redirect() returns a Redirector (not an Illuminate RedirectResponse),
// matching the convention in sibling components such as SwitchTeam.
public function mount()
{
$user = auth()->user();
// A team is already active, or the user has at most one team: nothing to pick.
if ($user->currentTeam() || $user->teams->count() <= 1) {
$resolved = $user->resolveStoredTeam();
if ($resolved) {
refreshSession($resolved);
}
return redirect()->route('dashboard');
}
}
public function selectTeam(int $teamId)
{
$user = auth()->user();
if (! $user->teams->contains('id', $teamId)) {
return;
}
$team = Team::find($teamId);
if (! $team) {
return;
}
refreshSession($team);
return redirect()->route('dashboard');
}
public function render(): View
{
return view('livewire.select-team', [
'teams' => auth()->user()->teams,
])->layout('layouts.simple');
}
}