Skip to content

[SecurityHttp] if don't have session,logout will throw SessionNotFoundException #42258

@mousezheng

Description

@mousezheng

Symfony version(s) affected: 5.2.4

Description
If not support of sessions in the app,getSession()wile throw SessionNotFoundException in the onLogout()

class SessionLogoutListener implements EventSubscriberInterface
{
    public function onLogout(LogoutEvent $event): void
    {
        $event->getRequest()->getSession()->invalidate();
    }

    public static function getSubscribedEvents(): array
    {
        return [
            LogoutEvent::class => 'onLogout',
        ];
    }
}

Possible Solution

Check if it has session before getSession()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions