mirror of
https://github.com/coollabsio/coolify.git
synced 2026-10-28 17:44:36 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Furox <177975472+Furox-Art@users.noreply.github.com> Co-authored-by: johandenhollander <johan.den.hollander@finalist.nl> Co-authored-by: João Cruz <161638790+SrJooJ@users.noreply.github.com> Co-authored-by: Saim Hashmi <hashmisaim037@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Laravel writes the whole session payload at the end of every request. A request
|
|
* that started before a team switch (for example a wire:poll update) would write the
|
|
* previous team back into the session, and the next request would make it permanent.
|
|
* When this request did not change the team itself, keep the team that is stored now.
|
|
*/
|
|
class KeepConcurrentTeamSwitch
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$teamIdAtStart = data_get($request->session()->get('currentTeam'), 'id');
|
|
|
|
$response = $next($request);
|
|
|
|
$session = $request->session();
|
|
if (data_get($session->get('currentTeam'), 'id') !== $teamIdAtStart) {
|
|
return $response;
|
|
}
|
|
|
|
$storedSession = clone $session;
|
|
$storedSession->start();
|
|
$storedTeam = $storedSession->get('currentTeam');
|
|
if ($storedTeam && data_get($storedTeam, 'id') !== $teamIdAtStart) {
|
|
$session->put('currentTeam', $storedTeam);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|