Logout doesnt work

hello,

i want to implement a simple login/logout function, so i check out Access forbidden | Kirby CMS.

i put in config.php

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

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

        go('login');

      }
    ]
  ]
];

in my default template:

<?php if ($user = $kirby->user()): ?>

      <a href="<?= url('logout') ?>">Logout</a>

  <?php endif ?>


when i hit the logout button it redirects to /logout, but on that page the logout button is still displayed (meaning still logged in?) and it didnt redirect to /login. what could be the reason?

tnx and regards
fusi

Should work, is the route the only code in your config?

hello texnixe, no, theres some more code in it:

<?php

return [

    'sylvainjule.bouncer.list' => [
        'manager' => [
            'fieldname' => 'canaccess'
        ]
    ]
];


return [
  
 
    'plugins' => [
     
        'fusi/clients' => true,
    ],
];



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

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

        go('login');

      }
    ]
  ]
];


?>




greetz, fusi

That’s what I thought. Note that all configuration options must go into a single return array. To understand why, check out what return does: PHP: return - Manual

And don’t use a closing PHP tag at the end of the file.

tnx a lot!!

regards
dr. n00b