VerifyToken.php 787 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\common\middleware;
  4. use app\exception\BaseException;
  5. use Jwt;
  6. use think\facade\Session;
  7. class VerifyToken
  8. {
  9. /**
  10. * @param $request
  11. * @param \Closure $next
  12. * @return mixed
  13. * @throws BaseException
  14. */
  15. public function handle($request, \Closure $next)
  16. {
  17. $url = $request->url();
  18. $has_login = strpos($url,'login');
  19. if($has_login !== false && $has_login >= 0) {
  20. return $next($request);
  21. }
  22. $session = Session::get("admin");
  23. if($session) {
  24. $jwt = Jwt::verifyToken($session);
  25. if ($jwt)
  26. return $next($request);
  27. }
  28. Session::set("admin", null);
  29. return redirect('/admin/login/index');
  30. }
  31. }