I try to redirect the user to the homepage when she/he logout from the panel.
In the config file I’ve added a route but it doesn’t works:
return [
'routes' => [
[
'pattern' => 'panel/logout',
'action' => function() {
if ( $user = $this->user() ) :
$user->logout();
endif;
go('/');
}
],
],
];
Any idea how to achieve this redirection in K3?
Hm, your route is not correct, the pattern would have to be auth/logout
and the method POST
But apart from that, I don’t know if you can override the native routes at all and if so, how.
Tried this but doesn’t work:
'routes' => [ // redirect logout to the homepage
[
'pattern' => 'auth/logout',
'method' => 'POST',
'action' => function() {
if ( $user = $this->user() ) :
$user->logout();
endif;
go('/');
}
],
],
You suggested a similar solution for Kirby 2: Redirect to home page instead of login page after logout
so I was hoping it would work for K3 too
npix
June 22, 2019, 10:03pm
4
I’m not that familiair enough with Kirby yet, but from a programming standpoint, is the logout a POST route?
Yes, that’s why I said that above.
auth.js
logout() {
return api.post("auth/logout");
}
And /kirby/config/api/routes/auth.php
[
'pattern' => 'auth/logout',
'method' => 'POST',
'auth' => false,
'action' => function () {
$this->kirby()->auth()->logout();
return true;
}
],
I had the same problem when I tried to override the /media/pages
route (see this post ). I could solve it with a route:before hook . This might work here, too!?
EDIT: Unfortunately this does not work for the panel, because you can’t make a server-side redirect on an ajax request (I guess).
Maybe we can do this with the new “panel” plugin? Didn’t try yet but will check it out …
I’m not yet very comfortable with plugins coding …