hhxsv5 / laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$request->user()在生产过程中获取值为null。

furleywolf opened this issue · comments

  1. Your software version (Screenshot of your startup)

    Software Version
    PHP 8.2.19
    Swoole 5.1.0
    Laravel/Lumen 9.52.16
  2. Detail description about this issue(error/log)

    在使用了\Laravel\Passport\Http\Middleware\CheckScopes后,初始调用正常,调用10余次会因为$request->user()为空出现异常。不是很清楚为什么swoole启动的时候是正常的,看了issue,都是在第二次获取不到,我是在第十次,很怪。

  3. Some reproducible code blocks and steps

    public function handle($request, $next, ...$scopes)
    {
        //此处会出现$request->user()  = null。
        if (! $request->user() || ! $request->user()->token()) {
            throw new AuthenticationException;
        }
    
        foreach ($scopes as $scope) {
            if (! $request->user()->tokenCan($scope)) {
                throw new MissingScopeException($scope);
            }
        }
    
        return $next($request);
    }

已加清理器,已配置中间件顺序,在执行到目标中间件时用户已登陆,但仍无法获取$request->user()。

`

  Hhxsv5\LaravelS\Illuminate\Cleaners\SessionCleaner::class, // If you use the session/authentication in your project, please uncomment this line
  Hhxsv5\LaravelS\Illuminate\Cleaners\AuthCleaner::class,    // If you use the authentication/passport in your project, please uncomment this line
  Hhxsv5\LaravelS\Illuminate\Cleaners\JWTCleaner::class,     // If you use the package "tymon/jwt-auth" in your project, please uncomment this line    

`

已通过不同的终端测试,重启/重载后,所有的终端(用户)都是正常的,共同请求10次左右后所有的都不正常。感觉和其他的几个issue很像,可以通过Auth::user()解决,但是很多包里的中间件要拎出来重写,感觉不太好。
#444 #413