CheckAuthMiddleware.php 523 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Models\User\User;
  4. use App\Modules\Admin\Services\AuthService;
  5. use Closure;
  6. use Illuminate\Auth\AuthenticationException;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Auth;
  9. class CheckAuthMiddleware
  10. {
  11. public function handle(Request $request, Closure $next)
  12. {
  13. $user = Auth::user();
  14. if (is_null($user)) {
  15. return response()->json([
  16. "code" => 401,
  17. ]);
  18. }
  19. return $next($request);
  20. }
  21. }