Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kinger251285's avatar

Jetstream Inertia Middleware redirects & if issues

Hi

I have a middleware that simply checks if a user is an admin, SuperAdmin or normal user. If either admin it redirects to the an inertia/jetstream admin panel. If not then it redirects to a blade templated front end.

Im having a couple issues where it checks admin fine and redirects. It checks SuperAdmin upon a manual visit but not during login (seems to ignore the SuperAdmin, should redirect after login) and if its not redirecting to the admin backend the front end redirect appears in a modal/iframe rather than redirecting the whole page.

My isAdmin middelware below:

	  $Admin = false;    

      if (Auth::user()->role == 'admin'){

        $Admin = true;

      }  

      if (Auth::user()->role == 'SuperAdmin'){

        $Admin = true;
        
      }            

      if ($Admin){
        return $next($request);
      } else {
        return Redirect::route('user.dashboard');
      }

'

0 likes
1 reply
kinger251285's avatar

Ive also tried but the same issue

	  $Admin = false;  
      if (Auth::user()->role == 'admin'){

        $Admin = true;

      }  

      if (Auth::user()->role == 'SuperAdmin'){

        $Admin = true;
        
      }            

      if ($Admin){            
        return $next($request);
      } else {

        
        $url = env('APP_URL');
        /*
        return Inertia::location($url.'/dashboard');
        //return Redirect::route('user.dashboard');
        */

        if ($request->ajax()) {
          return Inertia::location($url.'/dashboard');
        }

        return Redirect::route('user.dashboard');
      }

Please or to participate in this conversation.