Redirect specific user after logout to specific page

Hey Folks,
that is the basic for my user configuration. But the user has restricted access to specific pages in the the panel via the Plugin Bouncer | Kirby CMS Plugins.

I want to logout my client-user to the homepage and not to /panel/login page.
How should I root that?

I have read two concerning articles here (K2/K3). But there were no solution yet.

Hope anyone can help.

THX in advance

I am not fully sure what you are trying to achieve as the Bouncer plugin you link to handles access in the Panel and the article you linked to is restricting access on the frontend.

If it’s about the Panel you can overwrite the logout Panel area and implement your logic where to redirect: https://github.com/getkirby/kirby/blob/main/config/areas/logout.php

Docs on how to extend/overwrite core areas.

Hey, thx for your answer. Both, the article and the Plugin have no direct connection. I just want to show, what I want.

Well, i built up a site where a few Users will have access using the bouncer Plugin. There is also a frontend Login Page for these users. But when these users logout from panel, the will be redirected to /panel/login. I want them to route to a frontend page. So this is the question how to do that.
In the linked article there is the same question. But this is K2. So I hoped in K4 there is a solution to doing this.

Hope you understand what I want to figure out and maybe can help.
THX in advance.

Yes, you can do so:

Hej,

so I changed the route to:

<?php

use Kirby\Panel\Panel;
use Kirby\Toolkit\I18n;

return function ($kirby) {
	return [
		'icon'  => 'user',
		'label' => I18n::translate('logout'),
		'views' => [
			'logout' => [
				'pattern' => 'logout',
				'auth'    => false,
				'action'  => function () use ($kirby) {
					$kirby->auth()->logout();
					Panel::go('/intern');
				},
			]
		]
	];
};

But there is nothing happening… After logging out, I will be redirected to… panel/login.

Also I’ve tried in config.php:

 'routes' => [
         [
             'pattern' => 'logout',
             'action' => function () {

                 return go('/intern');
             }
         ]
     ],

And:

    'routes' => [
      [
     'pattern' => 'logout',
     'action'  => function() {

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

       go('/intern');

     }
   ]
 ],

Both has no effect on it ;/

This must then be go() instead of Panel::go(). But are modifying the source code here instead of overwriting the area? Not sure overwriting works, at least I couldn’t get it to work, maybe @distantnative has some example code.

Yes, it works fine… but it really doesn’t feel as good to change source code :thinking:

THX tor this. Maybe there is a netter solution… we will see.

That was indeed not the suggestion! As a rule, never touch the source code, any changes there will be overwritten with the next update.

The original idea was to overwrite the logout area in a plugin, but I must admit that I couldn’t get it to work, otherwise would have posted my solution.

This works for me

<?php

use Kirby\Cms\App;

App::plugin('my/logout', [
  'areas' => [
    'logout' => function () {
      return [
        'views' => [
          'logout' => [
            'action' => function () {
              App::instance()->auth()->logout();
			  go('/foo');
            }
          ]
        ]
      ];
    }
  ]
]);
1 Like

Hey Ho,

nice! This works very well! But now is the chellange to route only a specific user-role… At this moment admin also were redirected.

You can add a condition here that checks the user role.

if (App::instance()->user()?->isAdmin()) {
  Panel::go('login');
} else {
  go('/foo');
}

Hmm… maybe wrong place for the condition?
Now, there is happening nothing after logging out…

<?php

use Kirby\Cms\App;

App::plugin('my/logout', [
  'areas' => [
    'logout' => function () {
      return [
        'views' => [
          'logout' => [
            'action' => function () {
              if (App::instance()->user()?->isAdmin()) {
                Panel::go('login');
              } else {
                go('/foo');
              }
            }
          ]
        ]
      ];
    }
  ]
]);

You removed the logout bit…