> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-013b37f0.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Login Listeners

CometChat SDK provides you with a mechanism to get real-time status whenever a user logs into CometChat or logs out from CometChat.

Login Listener provides you with the below 4 methods:

| Delegate Method                            | Information                                                                                                                                 |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
| onLoginSuccess(user: User)                 | This method is triggered when the user successfully logs into the CometChat SDK. It returns an Object of the User loggedIn.                 |
| onLoginFailed(error: CometChatException?)  | This method is triggered when the user could not successfully log into the CometChat SDK. It returns an Object of the CometChatException.   |
| onLogoutSuccess()                          | This method is called when the user successfully logs out from the CometChat SDK. It does not return anything.                              |
| onLogoutFailed(error: CometChatException?) | This method is triggered when the user could not successfully log out of the CometChat SDK. It returns an Object of the CometChatException. |

In order to use the Delegate methods you must add protocol conformance `CometChatLoginDelegate` as `CometChat.logindelegate = self` . Here is the example of CometChatLoginDelegate:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    extension AppDelegate: CometChatLoginDelegate {

    	func onLoginSuccess(user: User) {
           print("Login Success")
        }
        
        func onLoginFailed(error: CometChatException?) {
            print("Login Failed")
        }
        
        func onLogoutSuccess() {
            print("Logout Success")
        }
        
        func onLogoutFailed(error: CometChatException?) {
            print("Logout Failed")
        }
    }
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    @interface ViewController ()<CometChatConnectionDelegate>

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        [CometChat logindelegate:self];
    }

    - (void)onLoginSuccess(user : User) {
        
        NSLog(@"onLoginSuccess");
    }

    - (void)onLoginFailed(error : CometChatException) {
        
        NSLog(@"onLoginFailed");
    }

    - (void)onLogoutSuccess() {
        
        NSLog(@"onLogoutSuccess");
    }

    - (void)onLogoutFailed(error : CometChatException) {
        
        NSLog(@"onLogoutFailed");
    }
    ```
  </Tab>
</Tabs>
