- Move middleware to App/ subdir (HandleInertiaRequests, HandleAppearance, EnsureSubscribed, EnsureUserSetupIsComplete) matching Sendkit pattern - Move all Form Requests into organized subdirs (App/Post, App/Workspace, App/Media, App/Invite, App/Settings, App/Auth) - Create AuthUserResource and AuthWorkspaceResource for HandleInertiaRequests shared data (role inside currentWorkspace, matching Sendkit pattern) - Split auth.php into 3 route groups (no middleware, guest, auth) matching Sendkit pattern exactly - Fix UserFactory to include all nullable attributes (current_workspace_id, stripe_id, pm_type, pm_last_four, trial_ends_at) - Fix SocialAccountResource (display_name not name) - Update frontend for new auth prop structure - 702 tests passing (2 pre-existing Mastodon failures)
55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware\App;
|
|
|
|
use App\Enums\User\Setup;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class EnsureUserSetupIsComplete
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param Closure(Request): (Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$user = $request->user();
|
|
|
|
if (! $user) {
|
|
return $next($request);
|
|
}
|
|
|
|
// If setup is completed, allow through
|
|
if ($user->setup === Setup::Completed) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Map setup status to allowed routes
|
|
$allowedRoutes = match ($user->setup) {
|
|
Setup::Role => ['onboarding.step1', 'onboarding.step1.store'],
|
|
Setup::Connections => ['onboarding.step2', 'onboarding.step2.store', 'social.*'],
|
|
Setup::Subscription => ['onboarding.complete', 'onboarding.step2'],
|
|
default => ['onboarding.step1', 'onboarding.step1.store'],
|
|
};
|
|
|
|
$currentRoute = $request->route()?->getName();
|
|
|
|
// Check if current route is allowed
|
|
foreach ($allowedRoutes as $pattern) {
|
|
if ($currentRoute === $pattern || fnmatch($pattern, $currentRoute ?? '')) {
|
|
return $next($request);
|
|
}
|
|
}
|
|
|
|
// Redirect to appropriate step
|
|
return match ($user->setup) {
|
|
Setup::Role => redirect()->route('app.onboarding.step1'),
|
|
Setup::Connections => redirect()->route('app.onboarding.step2'),
|
|
Setup::Subscription => redirect()->route('app.onboarding.step2'),
|
|
default => redirect()->route('app.onboarding.step1'),
|
|
};
|
|
}
|
|
}
|