NormalUserAuthenticate.php 933 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Illuminate\Contracts\Auth\Factory as Auth;
  5. use App\Exceptions\ApiException;
  6. class NormalUserAuthenticate
  7. {
  8. /**
  9. * The authentication guard factory instance.
  10. *
  11. * @var \Illuminate\Contracts\Auth\Factory
  12. */
  13. protected $auth;
  14. /**
  15. * Create a new middleware instance.
  16. *
  17. * @param \Illuminate\Contracts\Auth\Factory $auth
  18. */
  19. public function __construct(Auth $auth)
  20. {
  21. $this->auth = $auth;
  22. }
  23. /**
  24. * Handle an incoming request.
  25. *
  26. * @param \Illuminate\Http\Request $request
  27. * @param \Closure $next
  28. * @param string|null $guard
  29. * @return mixed
  30. * @throws ApiException
  31. */
  32. public function handle($request, Closure $next, $guard = null)
  33. {
  34. if(empty($request->user())){
  35. throw new ApiException(401);
  36. }
  37. return $next($request);
  38. }
  39. }