File tree 1 file changed +43
-0
lines changed
Filter options
1 file changed +43
-0
lines changed
Original file line number Diff line number Diff line change @@ -1723,6 +1723,49 @@ Next, you need to create a route for this URL (but not a controller):
1723
1723
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
+ Logout programmatically
1727
+ -----------------------
1728
+
1729
+ .. versionadded :: 6.2
1730
+
1731
+ The :class: `Symfony\B undle\S ecurityBundle\S ecurity\S ecurity <Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security> `
1732
+ class was introduced in Symfony 6.2. Prior to 6.2, it was called
1733
+ ``Symfony\Component\Security\Core\Security ``.
1734
+
1735
+ .. versionadded :: 6.2
1736
+
1737
+ The :method: `Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security::logout `
1738
+ method was introduced in Symfony 6.2.
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. ::
1743
+
1744
+ // src/Controller/SecurityController.php
1745
+ namespace App\Controller\SecurityController;
1746
+
1747
+ use App\Security\Authenticator\ExampleAuthenticator;
1748
+ use Symfony\Bundle\SecurityBundle\Security\Security;
1749
+
1750
+ class SecurityController
1751
+ {
1752
+ public function someAction(Security $security): Response
1753
+ {
1754
+ // 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);
1759
+
1760
+ if ($response !== null) {
1761
+ return $response;
1762
+ }
1763
+
1764
+ // Redirect to the homepage for instance
1765
+ // ...
1766
+ }
1767
+ }
1768
+
1726
1769
Customizing Logout
1727
1770
~~~~~~~~~~~~~~~~~~
1728
1771
You can’t perform that action at this time.
0 commit comments