Laravel Jetstream Inertia Non Intertia Routes Appearing in a Modal

Viewed 267

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.

The login redirect is set to go to /admin which is protected by the isAdmin middleware. Ive also tried only having a check for SuperAdmin however this is just ignored when logging in. If i navigate manually to the /admin route then the checks pass and i get access. So its working to some extent.

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 {

    
    $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');
  }
0 Answers
Related