public function actionChangeRole(string $email, string $role = 'client')
	{
		$trimmedEmail = trim($email);
		$trimmedRole = trim($role);
		
		$user = UserConsole::findByEmail($trimmedEmail);
		if (!$user) {
		
			Console::error("Email \"$trimmedEmail\" user doesn't exist");
			
			return ExitCode::UNSPECIFIED_ERROR;
		}
		
		$userId = $user->getId();
		$userEmail = $user->getEmail();
		
		// Initialize AuthManager and check current roles.
		$authManager = \Yii::$app->authManager;
		$assignments = $authManager->getAssignments($userId);
		Console::output("Assignments returned: " . json_encode($assignments));// Debugging.
		if (!empty($assignments)) {
			
			Console::output("User already assigned to a role. Revoking old roles...");
			foreach ($assignments as $assignment) {
				
				// Revoke the role if assignment is valid.
				if (is_object($assignment) && isset($assignment->roleName)) {
					if ($authManager->revoke($assignment->roleName, $userId)) {
						
						Console::output("Revoked role \"{$assignment->roleName}\" from user \"$trimmedEmail\".");
					}
					else {
						throw new Exception("Failed to revoke role \"{$assignment->roleName}\" from user \"$userEmail\".");
					}
				}
				else {
					Console::error("Invalid assignment data for user \"$trimmedEmail\".");
				}
			}
		}
		else {
			Console::output("User \"$userEmail\" has no assigned roles.");
		}
		
		// Check if the provided role exists.
		$authRole = $authManager->getRole($trimmedRole);
		if (!$authRole) {
			
			throw new Exception("Role \"$trimmedRole\" does not exist.");
		}
		
		$transaction = \Yii::$app->db->beginTransaction();
		try {
			// Assign the new role to the user.
			if ($authManager->assign($authRole, $userId)) {
				
				Console::output("Successfully assigned role \"$trimmedRole\" to user \"$userEmail\".");
			}
			else {
				throw new Exception("Failed to assign role \"$trimmedRole\" to user \"$userEmail\".");
			}
			
			// If all saves are successful, commit the transaction.
			$transaction->commit();
			
			Console::output("User role has been updated successfully.");
			Console::output("Email: " . $userEmail);
			Console::output("New Role: " . $trimmedRole);
			
			return ExitCode::OK;
		}
		catch (\Exception $e) {
		
			// An error occurred; roll back the transaction.
			$transaction->rollBack();
			
			Console::output("Role change failed: " . $e->getMessage());
				
			return ExitCode::UNSPECIFIED_ERROR;
		}
	}

./yii user/change-role <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS> helper
Assignments returned: {"client":{"userId":"37","roleName":"client","createdAt":1736122904}}
User already assigned to a role. Revoking old roles...
PHP Warning 'yii\base\ErrorException' with message 'Attempt to read property "name" on string'

in vendor/yiisoft/yii2/rbac/DbManager.php:902

I believe the code error is somewhere here:

				if (is_object($assignment) && isset($assignment->roleName)) {
					if ($authManager->revoke($assignment->roleName, $userId)) {
						
						Console::output("Revoked role \"{$assignment->roleName}\" from user \"$trimmedEmail\".");
					}
					else {
						throw new Exception("Failed to revoke role \"{$assignment->roleName}\" from user \"$userEmail\".");
					}
				}
				else {
					Console::error("Invalid assignment data for user \"$trimmedEmail\".");
				}