mirror of
https://gitee.com/mix-php/mix.git
synced 2024-12-02 03:37:56 +08:00
feat:examples: 优化中间件在无header时的处理
This commit is contained in:
parent
74f552262a
commit
2eb6cb105a
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user