Nami Public Documentation
SDK Reference
SDK Reference
  • NAMI
    • configure
    • NamiConfiguration
    • NamiLanguageCodes
  • NamiCampaignManager
    • launch
    • allCampaigns
    • isCampaignAvailable
    • refresh
    • registerAvailableCampaignsHandler
    • NamiCampaign
    • NamiCampaignRuleType
    • LaunchCampaignError
  • NamiCustomerManager
    • CustomerJourneyState
    • isLoggedIn
    • journeyState
    • loggedInId
    • login
    • logout
    • registerAccountStateHandler
    • registerJourneyStateHandler
    • setCustomerAttribute
    • getCustomerAttribute
    • clearCustomerAttribute
    • clearAllCustomerAttributes
  • NamiEntitlementManager
    • active
    • isEntitlementActive
    • NamiEntitlement
    • refresh
    • registerActiveEntitlementsHandler
  • NamiPaywallManager
    • dismiss
    • displayedViewController
    • registerSignInHandler
    • registerCloseHandler
    • registerBuySkuHandler
    • registerDeeplinkActionHandler
    • buySkuComplete
    • NamiPurchaseSuccess
    • NamiPaywallAction
    • NamiSKUType
  • NamiPurchaseManager
    • anySkuPurchased
    • consumePurchasedSku
    • NamiPurchase
    • NamiPurchaseState
    • NamiRestorePurchasesState
    • NamiSKU
    • presentCodeRedemptionSheet
    • registerPurchasesChangedHandler
    • registerRestorePurchasesHandler
    • restorePurchases
    • skuPurchased
  • NamiMLManager
    • coreAction
    • enterCoreContent
    • exitCoreContent
Powered by GitBook
On this page
  1. NamiCustomerManager

registerAccountStateHandler

PreviouslogoutNextregisterJourneyStateHandler

Last updated 11 months ago

Register a callback that will be called whenever or is called with results from those calls.

NamiCustomerManager.registerAccountStateHandler { accountStateAction, success, error in
   if success {
       if accountStateAction == .login {
         // logged in
       } else if accountStateAction == .logout {
         // logged out
       }        
   } else {
     // an error occured
   }
}
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}")
    }
}
}
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}");
    }
  }
});
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();
  };
}, []);
NamiCustomerManager.RegisterAccountStateHandler(accountStateCallback);
NamiCustomerManager.login
NamiCustomerManager.logout