请问如果使用的Sanctum 轻量级 API 认证,第二次通过request->user()结果为null 这么配置解决?
lwhdev opened this issue · comments
- 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 |
-
Detail description about this issue(error/log)
请问如果使用的Sanctum 轻量级 API 认证,第二次通过request->user()结果为null 这么配置解决? -
Some
reproducible
code blocks andsteps
'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
报错 内容 :
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)
同样遇到这个问题, 加了清除器没用.
用auth()->user() 好像能解决