diff --git a/app/Http/Middleware/TeamsPermission.php b/app/Http/Middleware/TeamsPermission.php index 41001ec..f9fa681 100644 --- a/app/Http/Middleware/TeamsPermission.php +++ b/app/Http/Middleware/TeamsPermission.php @@ -5,37 +5,16 @@ use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Spatie\Permission\PermissionRegistrar; class TeamsPermission { public function handle(Request $request, Closure $next) { - $user = Auth::user(); - - if (!$user) { - return redirect()->route('login')->with('error', 'You must be logged in to access this area.'); - } - - // Allow staff and admin users to access without team restrictions - if ($user->hasRole(['staff', 'admin'])) { - return $next($request); - } - - if (!$user->currentTeam) { - // Redirect to a default route or show an error - return redirect()->route('home')->with('error', 'You must be part of a team to access this area.'); - } - - // Check if the requested team matches the user's current team - $requestedTeamId = $request->route('tenant'); - if ($requestedTeamId && $requestedTeamId != $user->currentTeam->id) { - return redirect()->route('staff.dashboard', ['tenant' => $user->currentTeam->id]) - ->with('error', 'You do not have permission to access this team.'); + if (!empty($user = auth()->user()) && !empty($user->current_team_id)) { + app(PermissionRegistrar::class)->setPermissionsTeamId($user->current_team_id); } - // Check if the user has permission to access the current route - // You can implement your team-based permission logic here - return $next($request); } }