Customer Logout programmatically in Magento 2.

Magento 2, You can log out customer programmatically by getting current customer session using the Model file, Magento\Customer\Model\Session

You need to call logout() function from above class dependency.
Call below dependency in __construct function,

Call customerLogout() function from above file to programmatically log out a customer from the current session.

5 Replies to “Customer Logout programmatically in Magento 2.”

    1. It will be used using DI with Proxy injection to session class, I am aware about it but I have just show how to logout using Session class.

  1. Does magento 2.2.0 provide API for sign out? If not then how can I create it. I want to use it in my app


Leave a Reply