2023-11-17 01:44:01 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
2023-12-04 07:40:49 -05:00
|
|
|
use App\Exceptions\ApiException;
|
2023-11-17 01:44:01 -05:00
|
|
|
use App\Services\AuthService;
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
|
|
class User
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
2023-12-06 15:01:32 -05:00
|
|
|
if (!$authorization) throw new ApiException( '未登录或登陆已过期', 403);
|
2023-11-17 01:44:01 -05:00
|
|
|
|
|
|
|
$user = AuthService::decryptAuthData($authorization);
|
2023-12-06 15:01:32 -05:00
|
|
|
if (!$user) throw new ApiException('未登录或登陆已过期', 403);
|
2023-11-17 01:44:01 -05:00
|
|
|
$request->merge([
|
|
|
|
'user' => $user
|
|
|
|
]);
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|