EnsureAccountReady bundled a subscription gate (redirects to onboarding, SaaS only) with a workspace gate (redirects to workspace creation). The connect routes can't sit behind it because connecting/disconnecting happens during onboarding, before a subscription exists. Split the workspace gate into a standalone EnsureHasWorkspace middleware: - EnsureAccountReady is now subscription-only. - EnsureHasWorkspace redirects to workspace creation when there is no current workspace, in both SaaS and self-hosted modes. - The social connect group gains EnsureHasWorkspace; the main app group gains it alongside EnsureAccountReady (listed after it, so the subscription gate still runs first — no custom middleware priority). - The repeated `if (! $workspace) redirect()` guard is removed from the connect/store/authorize/disconnect/index/toggle handlers, and their return types are tightened (no more dangling RedirectResponse). LinkedIn connect's no-workspace path changes from a popup callback to the same redirect as the other platforms.
30 lines
756 B
PHP
30 lines
756 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware\App;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class EnsureHasWorkspace
|
|
{
|
|
/**
|
|
* Ensure the user has a current workspace, redirecting to workspace
|
|
* creation otherwise. Required in both SaaS and self-hosted modes — every
|
|
* authenticated app action operates on the current workspace.
|
|
*
|
|
* @param Closure(Request): (Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$user = $request->user();
|
|
|
|
if ($user && ! $user->currentWorkspace) {
|
|
return redirect()->route('app.workspaces.create');
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|