> For the complete documentation index, see [llms.txt](https://docs.namiml.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.namiml.com/sdk-reference/namicustomermanager/registeraccountstatehandler.md).

# registerAccountStateHandler

Register a callback that will be called whenever [`NamiCustomerManager.login`](/sdk-reference/namicustomermanager/login.md) or [`NamiCustomerManager.logout`](/sdk-reference/namicustomermanager/logout.md) is called with results from those calls.

{% tabs %}
{% tab title="Swift" %}

```swift
NamiCustomerManager.registerAccountStateHandler { accountStateAction, success, error in
   if success {
       if accountStateAction == .login {
         // logged in
       } else if accountStateAction == .logout {
         // logged out
       }        
   } else {
     // an error occured
   }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
NamiCustomerManager.registerAccountStateHandler { accountStateAction, success, error ->
if (success) {
    if (accountStateAction == AccountStateAction.LOGIN) {
        Log.d(LOG_TAG, "User is logged in")
    } else if (accountStateAction == AccountStateAction.LOGOUT) {
        Log.d(LOG_TAG, "User is logged out")
    }
} else if (error != null) {
    if (accountStateAction == AccountStateAction.LOGIN) {
        Log.d(LOG_TAG, "There was an error logging in. Error - ${error}")
    } else if (accountStateAction == AccountStateAction.LOGOUT) {
        Log.d(LOG_TAG, "There was an error logging out. Error - ${error}")
    }
}
}
```

{% endtab %}

{% tab title="Flutter" %}

```dart
NamiCustomerManager.registerAccountStateHandler()
    .listen((accountState) {
  print("AccountStateHandler triggered");

  if (accountState.success) {
    if (accountState.accountStateAction == AccountStateAction.login) {
      print("Login success");
    } else
    if (accountState.accountStateAction == AccountStateAction.logout) {
      print("Logout success");
    }
  } else {
    if (accountState.accountStateAction == AccountStateAction.login) {
      print("Login error - ${accountState.error}");
    } else
    if (accountState.accountStateAction == AccountStateAction.logout) {
      print("Logout error - ${accountState.error}");
    }
  }
});
```

{% endtab %}

{% tab title="React Native" %}

```jsx
useEffect(() => {
  checkIsLoggedIn();
  const subscriptionAccountStateRemover =
    NamiCustomerManager.registerAccountStateHandler(
      (action, success, error) => {
        console.log('accountState', action, success, error);
        if (action === 'login' && success) {
          setIsUserLogin(success);
          checkId();
        }
        if (action === 'logout' && success) {
          setIsUserLogin(!success);
          checkId();
        }
      },
    );
  return () => {
    subscriptionAccountStateRemover();
  };
}, []);
```

{% endtab %}

{% tab title="Unity" %}

```c
NamiCustomerManager.RegisterAccountStateHandler(accountStateCallback);
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.namiml.com/sdk-reference/namicustomermanager/registeraccountstatehandler.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
