Skip to content

Simplify logout #1459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still might be good for newcomers? It explains how the feature works internally

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that this "fake" logout route always felt weird for newcomers and created friction. I think it's better to just forget about this. If someone needs to do something advanced related to logout, they'll just find plenty of information about this in the Symfony Docs. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably makes sense 👍

}
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