feat:examples: 优化中间件在无header时的处理

This commit is contained in:
liujian 2022-05-21 22:23:15 +08:00
parent 74f552262a
commit 2eb6cb105a

View File

@ -19,7 +19,11 @@ class AuthMiddleware
{
return function (Context $ctx) {
try {
list(, $token) = explode(' ', $ctx->header('authorization'));
$auth = explode(' ', $ctx->header('authorization'));
if (count($auth) != 2) {
throw new \RuntimeException('Header Authorization not found');
}
list(, $token) = $auth;
$payload = JWT::decode($token, $_ENV['JWT_KEY'], ['HS256']);
} catch (\Throwable $e) {
$ctx->abortWithStatus(403);