@@ -1724,7 +1724,7 @@ That's it! By sending a user to the ``app_logout`` route (i.e. to ``/logout``)
1724
1724
Symfony will un-authenticate the current user and redirect them.
1725
1725
1726
1726
Logout programmatically
1727
- -----------------------
1727
+ ~~~~~~~~~~~~~~~~~~~~~~~
1728
1728
1729
1729
.. versionadded :: 6.2
1730
1730
@@ -1737,35 +1737,31 @@ Logout programmatically
1737
1737
The :method: `Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security::logout `
1738
1738
method was introduced in Symfony 6.2.
1739
1739
1740
- You can logout user programmatically using the `logout() ` method of the
1741
- :class: `Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security ` helper. The user will be logout from the current firewall
1742
- in the request. If the current request is not behind a firewall a ``\LogicException `` will be thrown. ::
1740
+ You can logout user programmatically using the ``logout() `` method of the
1741
+ :class: `Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security ` helper::
1743
1742
1744
1743
// src/Controller/SecurityController.php
1745
1744
namespace App\Controller\SecurityController;
1746
1745
1747
- use App\Security\Authenticator\ExampleAuthenticator;
1748
1746
use Symfony\Bundle\SecurityBundle\Security\Security;
1749
1747
1750
1748
class SecurityController
1751
1749
{
1752
1750
public function someAction(Security $security): Response
1753
1751
{
1754
1752
// logout the user in on the current firewall
1755
- $response = $this->security->logout();
1756
-
1757
- // You can also disable the csrf logout
1758
- $response = $this->security->logout(false);
1753
+ $response = $security->logout();
1759
1754
1760
- if ($response !== null) {
1761
- return $response;
1762
- }
1755
+ // you can also disable the csrf logout
1756
+ $response = $security->logout(false);
1763
1757
1764
- // Redirect to the homepage for instance
1765
- // ...
1758
+ // ... return $response (if set) or e.g. redirect to the homepage
1766
1759
}
1767
1760
}
1768
1761
1762
+ The user will be logout from the firewall of the request. If the request is
1763
+ not behind a firewall a ``\LogicException `` will be thrown.
1764
+
1769
1765
Customizing Logout
1770
1766
~~~~~~~~~~~~~~~~~~
1771
1767
0 commit comments