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

请问如果使用的Sanctum 轻量级 API 认证,第二次通过request->user()结果为null 这么配置解决?

lwhdev opened this issue · comments

commented
  1. Your software version (Screenshot of your startup)

| PHP | 7.3.0 |
| Swoole | 4.4.16 |
| LaravelS | 3.7.36 |
| Laravel Framework [local] | 7.30.6 |

  1. Detail description about this issue(error/log)
    请问如果使用的Sanctum 轻量级 API 认证,第二次通过request->user()结果为null 这么配置解决?

  2. Some reproducible code blocks and steps

    'register_providers'       => [],
  'cleaners'                 => [
      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
      // ...
  ],

中间件代码
```php`
public function handle($request, Closure $next)
{
$actionName = $request->route()->getActionName();
$actionName = str_replace('App\Http\Controllers\', '', $actionName);
$actionName = str_replace('\', '.', $actionName);
$actionName = str_replace('@', '.', $actionName);
$actionName = str_replace('Controller', '', $actionName);
$current_path = strtolower($actionName); //
$not_need_auth_list =[];

    $admin_auth_list = Redis::get(':admin::'.$request->user()->id); // 第二次会报错  $request->user()= null 
    if ($request->user()->is_supper){
         return $next($request);
    }else{
       
        return $next($request);
    }

}

``
#327

commented

报错 内容 :

 local.ERROR: Trying to get property 'id' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'id' of non-object at /home/www/app/Http/Middleware/AdminAuth.php:28)
commented

同样遇到这个问题, 加了清除器没用.
用auth()->user() 好像能解决