@@ -1796,7 +1796,7 @@ To enable logging out, activate the ``logout`` config parameter under your fire
1796
1796
main :
1797
1797
# ...
1798
1798
logout :
1799
- path : app_logout
1799
+ path : /logout
1800
1800
1801
1801
# where to redirect after logout
1802
1802
# target: app_any_route
@@ -1817,8 +1817,7 @@ To enable logging out, activate the ``logout`` config parameter under your fire
1817
1817
<!-- ... -->
1818
1818
1819
1819
<firewall name =" main" >
1820
- <!-- ... -->
1821
- <logout path =" app_logout" />
1820
+ <logout path =" /logout" />
1822
1821
1823
1822
<!-- use "target" to configure where to redirect after logout
1824
1823
<logout path="app_logout" target="app_any_route"/>
@@ -1838,30 +1837,28 @@ To enable logging out, activate the ``logout`` config parameter under your fire
1838
1837
$mainFirewall = $security->firewall('main');
1839
1838
// ...
1840
1839
$mainFirewall->logout()
1841
- // the argument can be either a route name or a path
1842
- ->path('app_logout')
1840
+ ->path('/logout')
1843
1841
1844
1842
// where to redirect after logout
1845
1843
// ->target('app_any_route')
1846
1844
;
1847
1845
};
1848
1846
1849
- ``path `` can be either a route name, or a URI.
1847
+ Symfony will then un-authenticate users navigating to the configured ``path ``,
1848
+ and redirect them to the configured ``target ``.
1850
1849
1851
- Since Symfony 6.4, you can leverage the
1852
- :class: `Symfony\\ Bundle\\ SecurityBundle\\ Routing\\ LogoutRouteLoader `
1853
- to automatically register a route for every logout URI you configured.
1854
- If your project uses :ref: `Symfony Flex <symfony-flex >`,
1855
- this is already done for you.
1856
- Otherwise, you need to import the ``security.route_loader.logout `` service
1857
- as a routing resource:
1850
+ If your project uses :ref: `Symfony Flex <symfony-flex >`, you're all set:
1851
+ the :class: `Symfony\\ Bundle\\ SecurityBundle\\ Routing\\ LogoutRouteLoader ` will
1852
+ automatically register a route for every logout URI you configured!
1853
+ Otherwise, you can enable this behavior yourself by importing the
1854
+ ``security.route_loader.logout `` service as a routing resource:
1858
1855
1859
1856
.. configuration-block ::
1860
1857
1861
1858
.. code-block :: yaml
1862
1859
1863
1860
# config/routes/security.yaml
1864
- logout :
1861
+ _symfony_logout :
1865
1862
resource : security.route_loader.logout
1866
1863
type : service
1867
1864
@@ -1891,8 +1888,10 @@ as a routing resource:
1891
1888
The :class: `Symfony\\ Bundle\\ SecurityBundle\\ Routing\\ LogoutRouteLoader ` was
1892
1889
introduced in Symfony 6.4.
1893
1890
1894
- Another option is to create a route matching the name or URI you configured as
1895
- ``path ``. You don't have to associate a controller because it wouldn't be called:
1891
+ Another option is to configure ``path `` as a route name, which can be useful if
1892
+ you want logout URIs to be translated according to the current locale e.g.
1893
+ In that case, you have to create this route yourself.
1894
+ Note that it doesn't need a controller, because it wouldn't be called anyways:
1896
1895
1897
1896
.. configuration-block ::
1898
1897
@@ -1906,7 +1905,10 @@ Another option is to create a route matching the name or URI you configured as
1906
1905
1907
1906
class SecurityController extends AbstractController
1908
1907
{
1909
- #[Route('/logout', name: 'app_logout', methods: ['GET'])]
1908
+ #[Route([
1909
+ 'en' => '/logout',
1910
+ 'fr' => '/deconnexion'
1911
+ ], name: 'app_logout', methods: ['GET'])]
1910
1912
public function logout(): never
1911
1913
{
1912
1914
// controller can be blank: it will never be called!
@@ -1918,7 +1920,9 @@ Another option is to create a route matching the name or URI you configured as
1918
1920
1919
1921
# config/routes.yaml
1920
1922
app_logout :
1921
- path : /logout
1923
+ path :
1924
+ en : /logout
1925
+ fr : /deconnexion
1922
1926
methods : GET
1923
1927
1924
1928
.. code-block :: xml
@@ -1930,7 +1934,10 @@ Another option is to create a route matching the name or URI you configured as
1930
1934
xsi : schemaLocation =" http://symfony.com/schema/routing
1931
1935
https://symfony.com/schema/routing/routing-1.0.xsd" >
1932
1936
1933
- <route id =" app_logout" path =" /logout" methods =" GET" />
1937
+ <route id =" app_logout" path =" /logout" methods =" GET" >
1938
+ <path locale =" en" >/logout</path >
1939
+ <path locale =" fr" >/deconnexion</path >
1940
+ </route >
1934
1941
</routes >
1935
1942
1936
1943
.. code-block :: php
@@ -1939,14 +1946,14 @@ Another option is to create a route matching the name or URI you configured as
1939
1946
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1940
1947
1941
1948
return function (RoutingConfigurator $routes): void {
1942
- $routes->add('app_logout', '/logout')
1949
+ $routes->add('app_logout', [
1950
+ 'en' => '/logout',
1951
+ 'fr' => '/deconnexion',
1952
+ ])
1943
1953
->methods(['GET'])
1944
1954
;
1945
1955
};
1946
1956
1947
- That's it! By sending a user to the ``app_logout `` route (i.e. to ``/logout ``)
1948
- Symfony will un-authenticate the current user and redirect them.
1949
-
1950
1957
Logout programmatically
1951
1958
~~~~~~~~~~~~~~~~~~~~~~~
1952
1959
0 commit comments