Redirect to home page instead of login page after logout

Hi,

My question is in the title :wink:

How to redirect the user on the hompage instead of the login page when the user logout from the panel?

You’d have to modify the core files. This is the logout method where the redirect happens:

  public function logout() {

    if($user = panel()->user()) {
      $user->logout();
    }

    $this->redirect('login');

  }

(/panel/app/controllers/auth.php)

1 Like

May I ovrerwrite this function with a plugin? I would prefer not to directly modify the Kirby core.

Hm, you can’t just overwrite the method, because it belongs to a class, so the only thing you could do is extend the class, but that would not help you.

I wonder if hijacking the logout route would be a way to achieve that, see this example of form hijacking https://github.com/lukaskleinschmidt/kirby-sortable-events/tree/modal/actions/event

Thanks Sonja, I will check this out :slight_smile:

Hi there @gillesvauvarin did you find a workaround for this? If so I am curious if you can share it?

Nop sorry, I didn’t find solution :-/

This seems to work:

<?php
if(!function_exists('panel')) return;

panel()->routes(array(
  array(
    'pattern' => '(logout)', // the trick here is the parens around the route pattern
    'method'  => 'GET|POST',
    'filter'  => array('auth'),
    'action'  => function() {
      if($user = panel()->user()) {
        $user->logout();
      }
      go('/');
    
    },
  ),
));

Thanks to @lukaskleinschmidt’s post

2 Likes

Thank you @texnixe and for that you are always on here in the forum, this solution worked like a perfectly . :smile: :star_struck: :sunglasses:

Just add this to your site/config/config.php

Check out this solution @gillesvauvarin