Beheben von Umleitungsproblemen mit der Slim 4-Authentifizierungs-Middleware
P粉949848849
P粉949848849 2023-08-13 12:04:52
0
1
487

我正在尝试使用中间件将未经身份验证的用户重定向到Google API身份验证。 如果我直接访问身份验证系统(通过访问/auth路由),Google部分可以工作,并且用户会被发送到我的主页。但是,如果我访问受中间件保护的页面,我会得到一个空白页面。

这是我的中间件:

withHeader('Location', '/auth')->withStatus(302); } else { $response = $handler->handle($request); } return $response; } }

由于Google部分可以工作,问题肯定在我的中间件中,对吗?这也意味着中间件的else部分是起作用的。 有什么建议吗?

TIA

P粉949848849
P粉949848849

Antworte allen (1)
P粉278379495

原来是因为我写这段代码的时候还没有喝足够的咖啡。 我忘记将变异的响应设置为一个变量。
在我的if语句内应该是:

$response = new Response(); $response = $response->withHeader('Location', '/auth')->withStatus(302);

第二行的 "$response =" 是我遗漏的部分。
希望这对其他人有所帮助。

    Neueste Downloads
    Mehr>
    Web-Effekte
    Quellcode der Website
    Website-Materialien
    Frontend-Vorlage
    Über uns Haftungsausschluss Sitemap
    Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!