feat : config
This commit is contained in:
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace App\Middleware\Api;
|
||||
|
||||
use App\Cache\Redis\Api\UserCache;
|
||||
use App\Constants\ApiCode;
|
||||
use App\Lib\ApiReturn;
|
||||
use App\Lib\Crypto\CryptoFactory;
|
||||
use Hyperf\Context\Context;
|
||||
use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
@@ -18,8 +21,16 @@ class JwtAuthMiddleware implements MiddlewareInterface
|
||||
protected HttpResponse $response,
|
||||
protected ApiReturn $apiReturn,
|
||||
protected CryptoFactory $cryptoFactory,
|
||||
protected UserCache $userCache,
|
||||
){}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
// 获取头部token
|
||||
@@ -39,7 +50,15 @@ class JwtAuthMiddleware implements MiddlewareInterface
|
||||
);
|
||||
}
|
||||
|
||||
Context::set('user_id',$userJwt['data']->id);
|
||||
$userId = $userJwt['data']->id;
|
||||
|
||||
if ($this->userCache->getUserToken($userId) != $authorization) {
|
||||
return $this->response->json(
|
||||
$this->apiReturn->error(ApiCode::getMessage(ApiCode::LOGIN_TOKEN_ERROR), ApiCode::LOGIN_TOKEN_ERROR)
|
||||
);
|
||||
}
|
||||
|
||||
Context::set('user_id',$userId);
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user