Logout-Function in FrontEnd

I want to offer a Logoutbutton in the FrontEnd.

I’d like to do via an ajax call.

The Member::logout is deprecated->Security::setCurrentUser(null)
-> that function has no effect

APi-docs tell me I could use SIlverStripe\Security\Security::logOut()
but if I call that function via URL I get an error…

Uncaught Exception Error: "Using $this when not in object context" at ...\site\vendor\silverstripe\framework\src\Security\Security.php line 726

Does anybody has a working solution for LogOut a User without the standard logout-page?

Thanks in advance

I use:

public function out(HTTPRequest $request)


In a controller


this can be placed wherever you want (remember to use Injector in the namespaces)

It will just log out the current logged in member, so you may also want to test if the member has logged in
if ($member = Member::currentUser()) { ... }

1 Like

You can use $LogoutURL in your frontend templates for the logout link