Skip to content

Commit

Permalink
minor #1459 Simplify logout (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the main branch.

Discussion
----------

Simplify logout

I checked the list of Symfony 6.4 features, and this is the only one that I think it fits this application. So, let's use it.

Commits
-------

10277e6 Simplify logout
  • Loading branch information
javiereguiluz committed Nov 24, 2023
2 parents d802a81 + 10277e6 commit 15962e8
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 15 deletions.
2 changes: 0 additions & 2 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ security:
#always_remember_me: true

logout:
# The route name the user can go to in order to logout
path: security_logout
# The name of the route to redirect to after logging out
target: homepage
# Secure the logout against CSRF
Expand Down
12 changes: 0 additions & 12 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,4 @@ public function login(
'error' => $helper->getLastAuthenticationError(),
]);
}

/**
* This is the route the user can use to logout.
*
* But, this will never be executed. Symfony will intercept this first
* and handle the logout automatically. See logout in config/packages/security.yaml
*/
#[Route('/logout', name: 'security_logout')]
public function logout(): void
{
throw new \Exception('This should never be reached!');
}
}
2 changes: 1 addition & 1 deletion tests/Controller/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testChangePassword(): void

$this->assertResponseRedirects();
$this->assertStringStartsWith(
'/en/logout',
'/logout',
$client->getResponse()->headers->get('Location') ?? '',
'Changing password logout the user.'
);
Expand Down

0 comments on commit 15962e8

Please sign in to comment.