fix : first finish

This commit is contained in:
2025-09-17 16:17:55 +08:00
parent 21331655f9
commit 082c15d697
15 changed files with 82 additions and 48 deletions

View File

@@ -8,6 +8,7 @@ use App\Common\Interface\JwtInterface;
use App\Constants\ResultCode;
use App\Exception\ErrException;
use App\Middleware\Token\AbstractTokenMiddleware;
use Hyperf\Context\Context;
use Lcobucci\JWT\Token\RegisteredClaims;
use Lcobucci\JWT\UnencryptedToken;
use function Hyperf\Support\env;
@@ -29,4 +30,13 @@ final class AdminTokenMiddleware extends AbstractTokenMiddleware
if ($audience !== env('APP_NAME') .'_admin') throw new ErrException('token错误',ResultCode::JWT_ERROR);
}
/**
* @param UnencryptedToken $token
* @return void
*/
public function setContext(UnencryptedToken $token): void
{
Context::set('current_admin_id',(int)$token->claims()?->get(RegisteredClaims::ID) ?? 0);
}
}