HarmonyOS Native SDK
User Account
Log Out

Log Out

logout

try {
  await userManager.logout();
} finally {
  unsubscribeUser();
  unsubscribeToken();
}

logout() requests cloud logout and clears the local user session in finally. The MQTT module observes token removal and releases cloud connections for the current user.

Do not log out merely because the account page disappears. Unsubscribe from page state instead.