Skip to content

Commit 5744c14

Browse files
authored
Update Jwt.php
1 parent f31b581 commit 5744c14

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

src/Middleware/Jwt.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace xiaodi\JWTAuth\Middleware;
66

77
use think\App;
8+
use think\Response;
89
use xiaodi\JWTAuth\Exception\JWTException;
910

1011
/**
@@ -21,37 +22,34 @@ public function __construct(App $app)
2122

2223
public function handle($request, \Closure $next, $store = null)
2324
{
24-
// 暂时修复 6.0.3 options 问题
25-
if ($request->isOptions()) {
26-
return $next($request);
25+
if ($request->method(true) == 'OPTIONS') {
26+
return Response::create()->code(204)->header($header);
2727
}
2828

2929
if (true === $this->app->get('jwt')->store($store)->verify()) {
3030

31-
$user = $this->app->get('jwt.user');
32-
33-
if ($user->getBind()) {
34-
if ($info = $user->get()) {
31+
if ($this->app->get('jwt.user')->bind()) {
32+
if ($user = $this->app->get('jwt.user')->find()) {
3533
// 路由注入
36-
$request->user = $info;
37-
34+
$request->user = $user;
35+
3836
// 绑定当前用户模型
39-
$model = $user->getClass();
40-
$this->app->bind($model, $info);
41-
37+
$class = $user->getClass();
38+
$this->app->bind($class, $user);
39+
4240
// 绑定用户后一些业务处理
4341
$this->bindUserAfter($request);
42+
} else {
43+
throw new JWTException('登录校验已失效, 请重新登录', 401);
4444
}
45-
} else {
46-
throw new JWTException('登录校验已失效, 请重新登录', 401);
4745
}
48-
46+
4947
return $next($request);
5048
}
5149

5250
throw new JWTException('Token 验证不通过', 401);
5351
}
54-
52+
5553
protected function bindUserAfter($request)
5654
{
5755
// 当前用户

0 commit comments

Comments
 (0)