Skip to content

Commit 875f78d

Browse files
authored
fix: connections will now auto connect if default credentials work (#1808)
Adds an automatic way to create a connection if the default credentials work (username = default, password = '') Closes HDX-3504 Closes HDX-3505
1 parent 34c9afe commit 875f78d

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎.changeset/tiny-hounds-sniff.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
fix: connections will automatically connect in clickstack build if default credentials test succeeds

‎packages/app/src/components/OnboardingModal.tsx‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { memo, useCallback, useEffect, useState } from 'react';
2+
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse/browser';
23
import {
34
MetricsDataType,
45
MetricTable,
@@ -245,6 +246,47 @@ function OnboardingModalComponent({
245246
const [hasAutodetected, setHasAutodetected] = useState(false);
246247
const [autoDetectedSources, setAutoDetectedSources] = useState<TSource[]>([]);
247248

249+
// Auto-connect for clickstack build: test default credentials against origin
250+
const [hasAttemptedAutoConnect, setHasAttemptedAutoConnect] = useState(false);
251+
useEffect(() => {
252+
if (!IS_CLICKHOUSE_BUILD) return;
253+
if (step !== 'connection') return;
254+
if (connections?.length !== 0) return;
255+
if (hasAttemptedAutoConnect) return;
256+
// lets try to auto connect to the origin clickhouse server
257+
setHasAttemptedAutoConnect(true);
258+
const host = window.location.origin;
259+
const client = new ClickhouseClient({
260+
host,
261+
username: 'default',
262+
password: '',
263+
});
264+
client
265+
.query({ query: 'SELECT 1', shouldSkipApplySettings: true })
266+
.then(result => {
267+
result.json().then(() => {
268+
createConnectionMutation.mutate(
269+
{
270+
connection: {
271+
name: 'Default',
272+
host,
273+
username: 'default',
274+
password: '',
275+
},
276+
},
277+
{
278+
onSuccess: () => {
279+
setStep('auto-detect');
280+
},
281+
},
282+
);
283+
});
284+
})
285+
.catch(() => {
286+
// Auto-connect failed, user will use the form manually
287+
});
288+
}, [step, connections, hasAttemptedAutoConnect, createConnectionMutation]);
289+
248290
const handleAutoDetectSources = useCallback(
249291
async (connectionId: string) => {
250292
try {
@@ -693,7 +735,9 @@ function OnboardingModalComponent({
693735
connection={{
694736
id: '',
695737
name: 'Default',
696-
host: 'http://localhost:8123',
738+
host: IS_CLICKHOUSE_BUILD
739+
? window.location.origin
740+
: 'http://localhost:8123',
697741
username: 'default',
698742
password: '',
699743
}}

0 commit comments

Comments
 (0)