亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Resolving redirect issues with Slim 4 authentication middleware
P粉949848849
P粉949848849 2023-08-13 12:04:52
0
1
734
<p>我正在嘗試使用中間件將未經(jīng)身份驗(yàn)證的用戶重定向到Google API身份驗(yàn)證。 如果我直接訪問身份驗(yàn)證系統(tǒng)(通過訪問/auth路由),Google部分可以工作,并且用戶會被發(fā)送到我的主頁。但是,如果我訪問受中間件保護(hù)的頁面,我會得到一個空白頁面。</p><p> 這是我的中間件:</p> <pre class="brush:php;toolbar:false;"><?php declare(strict_types=1); namespace AppMiddleware; use SlimPsr7Response; use PsrHttpMessageServerRequestInterface as Request; use PsrHttpServerRequestHandlerInterface as RequestHandler; class Auth { public function __invoke(Request $request, RequestHandler $handler): Response { if (!isset($_SESSION['access_token'])) { $response = new Response(); $response->withHeader('Location', '/auth')->withStatus(302); } else { $response = $handler->handle($request); } return $response; } }</pre> <p>由于Google部分可以工作,問題肯定在我的中間件中,對嗎?這也意味著中間件的else部分是起作用的。 有什么建議嗎?</p><p> TIA</p>
P粉949848849
P粉949848849

reply all(1)
P粉278379495

It turns out that it’s because I didn’t drink enough coffee when I wrote this code. I forgot to set the mutated response to a variable.
Inside my if statement it should be:

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

The "$response =" in the second line is the part I missed.
Hope this helps others.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template