Hpw to handle auto inactivity session out

after auto inactivity session out i want to redirect to a page according to controller .
if i’m in userscontroller it should redirect to users/index,
if i’m in pagescontroller it should redirect to pages/index…
Is there any solution?
I’m using cakephp 3.6

Anything at Application layer can be done from AppController.
Have a condition to check if the user is auth, and then redirect to ‘action’ => ‘index’.

Yes
But after session out/ auto logout app controller unable to get the particular controller.
Only redirect to default auth redirect
Can give me one example??

You could set a cookie each time you change for another controller.
Or handle it with some javascript such as :
document.addEventListener(“click”, function() {
$.ajax({
url:’/users/isconnected/’,
complete: function (response) {
if (response.responseText == “” || response.responseText == undefined) {
window.location.href = “value_of_cookie/index”;
}
}
});
return false;
});