When I check on a live server however, the first time I log out it works correctly. But if I log back in and log out again, it does not work. When clicking the âlog outâ button I am routed to the home page and I remain logged in.
Does anybody have an idea of which angle I could start debugging this from?
That seems right. So I think you are indeed logged out, but you get a cached representation of the page.
Please try sending a Cache-Control: private, no-cache header when a user is logged in:
header('Cache-Control: private, no-cache');
This should prevent your browser from using the cached response from the first visit. If that solves it, we will fix it in the upcoming Kirby release. Please let me know.
I tried adding the header in the login.php controller after the authentication and before the go(), however the issue still remains. Would that be the best place for it?
I have tried across browsers, and also updated to the latest version of Kirby, but this has not fixed it either.
Extra note
On Safari it works slightly differently, if I log in then log out and navigate to other pages that have if statements such as (if logged in show this), it believes I am still logged in and shows the content for a logged in user.
You will need the header on each page that contains user-specific information, not just on the login page itself. For testing you can put it into the templates of the affected pages inside the âif logged in show thisâ blocks.
After you made the change, make sure to clear the browser cache again before testing.
As I wrote, we will fix this in the upcoming release, so you only need this change temporarily.
Hey @lukasbestle, thanks for that info and the support.
I added the header() to all pages within an âif logged inâ block, cleared the browser cache and tested it again.
Even though I can see in dev tools the âcache-control :private, no-cacheâ under the Response Headers, it is still having a lot of issues. After that second Log in and Log out, the header is being added on some pages, but not on others and the issues still remains with the:
logout redirects to â login which redirects to â home
I have a site where some pages are password protected. The password protected pages are setup to redirect to a login page if !$kirby->user(). The email address is hard coded into the login controller, so users just need a password.
In the front end nav there is a link that shows a log out button, only for logged in users
This logout link seems to work erratically, sometimes it will work, then i log in again and it will not work. i will get redirected to the /success page, but the logout link will still be visible in the nav, meaning im still logged in.
I donât have any caching turned on. any ideas what might cause this?
opening dev tools and disabling the cache does seem to fix this.
changing the logout url to /logout?1 or /logout?2 seems to fix this. But each url just works once, like the browser is somehow caching it.
Looks like the user is not removed from the session, if you look at the session value, it doesnât change on logout like it should. What I canât tell why. Maybe Dreamhost has some caching enabled?