救救救小白求助 JWTAuth::process()

Allen_12138

问题描述

app\middleware\JWTAuth::process(): Return value must be of type support\Response, Webman\Http\Response returned
已指明返回類型,仍是報錯

报错信息

app\\middleware\\JWTAuth::process(): Return value must be of type support\\Response, Webman\\Http\\Response returned

截图报错信息里报错文件相关代码

截图
中間件
截图
截图

285 4 0
4个回答

Gin

中间内 那俩换成
use Webman\Http\Request;
use Webman\Http\Response;

  • 暂无评论
Tinywan

一个很简单的插件竟然被用的这么复杂

  • 暂无评论
Allen_12138

未解决,换了一种取值方式,不能直接userInfo取值了
$token = JwtToken::getExtend();

  • 暂无评论
Tinywan

中间件正确使用方式

declare(strict_types=1);

namespace app\middleware;

use Tinywan\ExceptionHandler\Exception\ForbiddenHttpException;
use Tinywan\Jwt\JwtToken;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;

class AuthorizationMiddleware implements MiddlewareInterface
{
    /**
     * @param Request $request
     * @param callable $handler
     * @return Response
     * @throws ForbiddenHttpException
     */
    public function process(Request $request, callable $handler): Response
    {
        $request->userId = JwtToken::getCurrentId();
        if (0 === $request->userId) {
            throw new ForbiddenHttpException();
        }
        return $handler($request);
    }
}
  • 暂无评论
×
🔝