| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- declare (strict_types = 1);
- namespace app\common\middleware;
- use app\exception\BaseException;
- use Jwt;
- use think\facade\Session;
- class VerifyToken
- {
- /**
- * @param $request
- * @param \Closure $next
- * @return mixed
- * @throws BaseException
- */
- public function handle($request, \Closure $next)
- {
- $url = $request->url();
- $has_login = strpos($url,'login');
- if($has_login !== false && $has_login >= 0) {
- return $next($request);
- }
- $session = Session::get("admin");
- if($session) {
- $jwt = Jwt::verifyToken($session);
- if ($jwt)
- return $next($request);
- }
- Session::set("admin", null);
- return redirect('/admin/login/index');
- }
- }
|