Repository: n8n-io/n8n
File: packages/frontend/editor-ui/src/features/credentials/quickConnect/composables/useQuickConnect.ts (TypeScript)

Code before:
			popup.open();
		});
	}

	async function connectViaBackendFlow(quickConnectOption: QuickConnectOption) {
		loading.value = true;
		return await getQuickConnectApiKey(rootStore.restApiContext, quickConnectOption);
	}

	async function getCredentialData(quickConnectOption: QuickConnectOption): Promise<object> {
		switch (quickConnectOption.quickConnectType) {
			case 'pinecone':
				return await connectToPinecone(quickConnectOption as QuickConnectPineconeOption);
			case 'firecrawl':
				return await connectViaBackendFlow(quickConnectOption);
			default:
				throw new Error(
					`Quick connect for type ${quickConnectOption.quickConnectType} is not implemented`,
				);
		}
	}

	async function connect(connectParams: {
		credentialTypeName: string;
		nodeType: string;
		source: string;
		serviceName: string;
	}): Promise<ICredentialsResponse | null> {
		const { credentialTypeName, nodeType, source } = connectParams;

		telemetry.track('User clicked quick connect button', {
			source,
			credential_type: credentialTypeName,
			node_type: nodeType,
		});

		if (isOAuthCredentialType(credentialTypeName)) {
			const credential = await createAndAuthorize(credentialTypeName, nodeType);
			return credential;
		}

		const quickConnectOption = getQuickConnectOption(credentialTypeName, nodeType);
		if (quickConnectOption) {
			const credentialType = credentialsStore.getCredentialTypeByName(credentialTypeName);
			if (!credentialType) {
				return null;
			}

			try {
				if (quickConnectOption.consentText) {
					const confirmed = await message.confirm(

Review comment (suggestion):
with splice and foreach we remove the handlers from the `cleanUpHandlers` and iterate over all in the came line

Code after:

			popup.open();
			cleanUpHandlers.push(() => popup.cleanup());
		});
	}

	async function connectViaBackendFlow(quickConnectOption: QuickConnectOption) {
		loading.value = true;
		return await getQuickConnectApiKey(rootStore.restApiContext, quickConnectOption);
	}

	async function getCredentialData(quickConnectOption: QuickConnectOption): Promise<object | null> {
		switch (quickConnectOption.quickConnectType) {
			case 'pinecone':
				return await connectToPinecone(quickConnectOption as QuickConnectPineconeOption);
			case 'firecrawl':
				return await connectViaBackendFlow(quickConnectOption);
			default:
				throw new Error(
					`Quick connect for type ${quickConnectOption.quickConnectType} is not implemented`,
				);
		}
	}

	function cleanUpDanglingHandlers() {
		cleanUpHandlers.splice(0, cleanUpHandlers.length).forEach((handler) => {
			try {
				handler();
			} catch {}
		});
	}

	onBeforeUnmount(cleanUpDanglingHandlers);

	async function connect(connectParams: {
		credentialTypeName: string;
		nodeType: string;
		source: string;
		serviceName: string;
	}): Promise<ICredentialsResponse | null> {
		cleanUpDanglingHandlers();
		const { credentialTypeName, nodeType, source } = connectParams;

		telemetry.track('User clicked quick connect button', {
			source,
			credential_type: credentialTypeName,
			node_type: nodeType,
		});

		if (isOAuthCredentialType(credentialTypeName)) {
			const credential = await createAndAuthorize(credentialTypeName, nodeType);