How to redirect on same page when user login after session expire in cake php 3.6?

Hi,

How to redirect on same page when user login after session expire in cake php 3.6?

Thanks in advance!

Regards
Anuj

I have the same problem. Could you solve it? If so, how?

Hi @anujg1,

Authentication plugin handles this by default, you just need to set queryParam config as shown in the documentation of the plugin.

src/Application.php

public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
{
    $service = new AuthenticationService();

    $service->setConfig([
        'unauthenticatedRedirect' => '/users/login',
        'queryParam' => 'redirect',
    ]);

    // your other code goes here...

    return $service;
}

With AuthComponent which probably you’re using for CakePHP 3.*, it’s the same it appends redirect query string as shown the the code here, and when you login it checks for this query params exists as show here in the code and redirects accordingly.

So when session expires and you reload the page it will be default append the redirect query params.

1 Like