File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ $ php think jwt:make
2929* ` model ` 用户模型
3030* ` refresh ` Token过期抛异常code = 50001
3131* ` relogin ` Token失效异常code = 50002
32- * ` automaticRenewal ` [ 开启过期自动续签] ( # 过期自动续签)
32+ * ` automaticRenewal ` [ 开启过期自动续签] ( 过期自动续签 )
3333
3434以下两个异常都会抛一个HTTP异常 StatusCode = 401
3535* ` xiaodi\Exception\HasLoggedException `
@@ -142,10 +142,6 @@ return [
142142
143143` automaticRenewal => true `
144144
145- 满足以下条件 就可以实现过期自动续签
146-
147- * Token 刷新时间 必须是在有效时间内
148-
149145系统检测到 Token 已过期, 会自动续期并返回以下 header 信息。
150146
151147* Automatic-Renewal-Token
Original file line number Diff line number Diff line change 1414class Jwt
1515{
1616 private $ app ;
17- private $ user ;
1817
19- public function __construct (App $ app, User $ user )
18+ public function __construct (App $ app )
2019 {
2120 $ this ->app = $ app ;
22- $ this ->user = $ user ;
2321 }
2422
2523 public function handle ($ request , \Closure $ next , $ type = 'admin ' )
2624 {
2725 if (true === $ this ->app ->jwt ->config ($ type )->verify ()) {
26+
27+ $ user = $ this ->app ['jwt.user ' ];
2828 // 自动注入用户模型
29- if ($ this -> user ->hasInject ()) {
30- $ user = $ this -> user ->get ();
29+ if ($ user ->hasInject ()) {
30+ $ userModel = $ user ->get ();
3131 // 路由注入
32- $ request ->user = $ user ;
32+ $ request ->user = $ userModel ;
3333
3434 // 绑定当前用户模型
35- $ model = $ this -> user ->getModel ();
36- $ this ->app ->bind ($ model , $ user );
35+ $ model = $ user ->getModel ();
36+ $ this ->app ->bind ($ model , $ userModel );
3737 }
3838
3939 return $ next ($ request );
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ public function getModel()
5656 public function get (): Model
5757 {
5858 $ token = $ this ->jwt ->getToken ();
59-
59+
6060 if (!$ token ) {
6161 throw new JWTException ('未登录. ' , 500 );
6262 }
You can’t perform that action at this time.
0 commit comments