2 years ago

Can I get this cookie in middleware right away?

Posted 2 years ago by jediping

I’ve got a single sign-on emulator that does a redirect and sets a cookie. I’ve got a middleware (GenerateMenus) that checks the cookie and loads the auth information from the SSO emulator, rather than the default auth stuff, if that cookie is set. It works fine except right after clicking the login button.

The GenerateMenus middleware is called before the cookie appears, so it thinks the user isn’t logged in and gives the wrong display. Once the page loads, a refresh or form submit will give the right menu.

So, I think the cookie is being set after the middleware runs. Any looking at cookies I do before then doesn't show the new cookie. Any ideas on how to find this cookie before it becomes a cookie? scratches head

Setting the cookie:

return redirect()
                ->withCookies([SsoEmulator::BakeCookie($member_id, $member_data)]);

The cookie check that fails:


My web middleware group:

'web' => [            // Utilize custom cookie encryter.
            // \Illuminate\Session\Middleware\AuthenticateSession::class,

Please sign in or create an account to participate in this conversation.