Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): keep OAuth source connection inside onboarding (#66309)

Tom Owersc7ffa6e49b00
diff --git a/frontend/src/scenes/onboarding/legacy/data-warehouse/DataWarehouseQueryVariant.tsx b/frontend/src/scenes/onboarding/legacy/data-warehouse/DataWarehouseQueryVariant.tsx
index 57d74adea1ef..2c432d155c70 100644
--- a/frontend/src/scenes/onboarding/legacy/data-warehouse/DataWarehouseQueryVariant.tsx
+++ b/frontend/src/scenes/onboarding/legacy/data-warehouse/DataWarehouseQueryVariant.tsx
@@ -24,7 +24,7 @@ import { InlineSourceSetup } from 'products/data_warehouse/frontend/shared/compo
import { onboardingLogic } from '../onboardingLogic'
import { OnboardingStep } from '../OnboardingStep'
-import { ConnectorIconGrid, DataWarehouseOnboardingLoadingPlaceholder } from './components'
+import { ConnectorIconGrid, DataWarehouseOnboardingLoadingPlaceholder, initialOnboardingPhase } from './components'
// The query skeleton is fixed — SELECT, FROM, JOIN, ON stay put.
// Only the slots (comment, columns, source, posthog table, on clause,
@@ -157,7 +157,7 @@ function DataWarehouseQueryInner(): JSX.Element {
const { reportOnboardingStepCompleted } = useActions(eventUsageLogic)
const { availableSourcesLoading } = useValues(availableSourcesLogic)
const { connectors } = useValues(sourceWizardLogic)
- const [phase, setPhase] = useState<'value-prop' | 'setup'>('value-prop')
+ const [phase, setPhase] = useState<'value-prop' | 'setup'>(initialOnboardingPhase)
const [sceneIndex, setSceneIndex] = useState(0)
const visibleConnectors = connectors.filter((c: SourceConfig) => !c.unreleasedSource)
diff --git a/frontend/src/scenes/onboarding/legacy/data-warehouse/DataWarehouseValuePropVariant.tsx b/frontend/src/scenes/onboarding/legacy/data-warehouse/DataWarehouseValuePropVariant.tsx
index 831e169d9edb..93cba4f059a9 100644
--- a/frontend/src/scenes/onboarding/legacy/data-warehouse/DataWarehouseValuePropVariant.tsx
+++ b/frontend/src/scenes/onboarding/legacy/data-warehouse/DataWarehouseValuePropVariant.tsx
@@ -21,7 +21,7 @@ import { InlineSourceSetup } from 'products/data_warehouse/frontend/shared/compo
import { onboardingLogic } from '../onboardingLogic'
import { OnboardingStep } from '../OnboardingStep'
-import { ConnectorIconGrid, DataWarehouseOnboardingLoadingPlaceholder } from './components'
+import { ConnectorIconGrid, DataWarehouseOnboardingLoadingPlaceholder, initialOnboardingPhase } from './components'
const EXAMPLE_QUERIES = [
{
@@ -71,7 +71,7 @@ function DataWarehouseValuePropInner(): JSX.Element {
const { reportOnboardingStepCompleted } = useActions(eventUsageLogic)
const { availableSourcesLoading } = useValues(availableSourcesLogic)
const { connectors } = useValues(sourceWizardLogic)
- const [phase, setPhase] = useState<'value-prop' | 'setup'>('value-prop')
+ const [phase, setPhase] = useState<'value-prop' | 'setup'>(initialOnboardingPhase)
const visibleConnectors = connectors.filter((c: SourceConfig) => !c.unreleasedSource)
diff --git a/frontend/src/scenes/onboarding/legacy/data-warehouse/components.tsx b/frontend/src/scenes/onboarding/legacy/data-warehouse/components.tsx
index a2a760cd20ca..90bcb2f22784 100644
--- a/frontend/src/scenes/onboarding/legacy/data-warehouse/components.tsx
+++ b/frontend/src/scenes/onboarding/legacy/data-warehouse/components.tsx
@@ -15,6 +15,12 @@ export function DataWarehouseOnboardingLoadingPlaceholder(): JSX.Element {
)
}
+// An OAuth round-trip returns to this step with ?kind=<source>; start on the setup phase so
+// InlineSourceSetup is mounted to resume the wizard rather than showing the value-prop screen.
+export function initialOnboardingPhase(): 'value-prop' | 'setup' {
+ return new URLSearchParams(window.location.search).get('kind') ? 'setup' : 'value-prop'
+}
+
export function useDataWarehouseLoadingState(): { isLoading: boolean } {
const { availableSources, availableSourcesLoading } = useValues(availableSourcesLogic)
return { isLoading: availableSourcesLoading || availableSources === null }
diff --git a/products/data_warehouse/frontend/shared/components/InlineSourceSetup.tsx b/products/data_warehouse/frontend/shared/components/InlineSourceSetup.tsx
index 14ac13d483e7..a921cb48bac6 100644
--- a/products/data_warehouse/frontend/shared/components/InlineSourceSetup.tsx
+++ b/products/data_warehouse/frontend/shared/components/InlineSourceSetup.tsx
@@ -1,5 +1,6 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { useState } from 'react'
+import { router } from 'kea-router'
+import { useEffect, useState } from 'react'
import { IconDatabase, IconPlus } from '@posthog/icons'
import { LemonButton, LemonCard, LemonSkeleton } from '@posthog/lemon-ui'
@@ -41,6 +42,8 @@ function InternalInlineSourceSetup({
}: InlineSourceSetupProps): JSX.Element {
const { connectors } = useValues(sourceWizardLogic)
const { onClear } = useActions(sourceWizardLogic)
+ const { searchParams, location } = useValues(router)
+ const { replace } = useActions(router)
const [currentView, setCurrentView] = useState<InlineSourceSetupView>('selection')
const [selectedSource, setSelectedSource] = useState<ExternalDataSourceType | null>(null)
@@ -48,6 +51,27 @@ function InternalInlineSourceSetup({
// Filter out unreleased sources
const availableConnectors = connectors.filter((c: SourceConfig) => !c.unreleasedSource)
+
+ // Resume an OAuth round-trip: an OAuth source redirects the whole page to the provider and
+ // back to this onboarding URL with ?kind=<source>. On mount, re-open the wizard for that
+ // source so the user lands back where they left off (credentials are restored by the wizard
+ // from the state saved before the redirect). Runs once — subsequent picks use the grid.
+ useEffect(() => {
+ const kind = searchParams.kind
+ if (!kind) {
+ return
+ }
+ const match = availableConnectors.find((c) => c.name.toLowerCase() === String(kind).toLowerCase())
+ if (match) {
+ setSelectedSource(match.name)
+ setCurrentView('connecting')
+ }
+ // Consume the param so a later remount (refresh, back-navigation, cancel) doesn't force the
+ // wizard back open after the connection has already been handled.
+ const { kind: _kind, ...restParams } = searchParams
+ replace(location.pathname, restParams)
+ // oxlint-disable-next-line react-hooks/exhaustive-deps
+ }, [])
const featuredSources = availableConnectors.filter((c: SourceConfig) => c.featured)
const hiddenSources = availableConnectors.filter((c: SourceConfig) => !c.featured)
const sourcesToShow = expanded ? availableConnectors : featuredSources
diff --git a/products/data_warehouse/frontend/shared/components/forms/IntegrationChoice.tsx b/products/data_warehouse/frontend/shared/components/forms/IntegrationChoice.tsx
index 9aea1898ea81..44be7aeb50ff 100644
--- a/products/data_warehouse/frontend/shared/components/forms/IntegrationChoice.tsx
+++ b/products/data_warehouse/frontend/shared/components/forms/IntegrationChoice.tsx
@@ -1,4 +1,5 @@
-import { useActions } from 'kea'
+import { useActions, useValues } from 'kea'
+import { router } from 'kea-router'
import {
IntegrationChoice,
@@ -20,12 +21,29 @@ export function SourceIntegrationChoice({
...props
}: SourceIntegrationChoiceProps): JSX.Element {
const { saveFormStateBeforeRedirect } = useActions(sourceWizardLogic)
+ const { location } = useValues(router)
const sourceKind = sourceConfig.name.toLowerCase()
+
+ // In onboarding the wizard is embedded in the page. A full-page OAuth redirect to the
+ // standalone new-source scene would drop the user out of the onboarding flow, so when we're
+ // on an onboarding route we return to the current onboarding URL with the source kind instead.
+ // InlineSourceSetup reads that kind on mount and resumes the wizard (credentials are restored
+ // from the state saved by beforeRedirect). Outside onboarding the standalone scene is correct.
+ const isOnboarding = location.pathname.includes('/onboarding')
+ let redirectUrl: string
+ if (isOnboarding) {
+ const params = new URLSearchParams(location.search)
+ params.set('kind', sourceKind)
+ redirectUrl = `${location.pathname}?${params.toString()}`
+ } else {
+ redirectUrl = urls.dataWarehouseSourceNew(sourceKind)
+ }
+
return (
<IntegrationChoice
{...props}
integration={integration ?? sourceKind}
- redirectUrl={urls.dataWarehouseSourceNew(sourceKind)}
+ redirectUrl={redirectUrl}
beforeRedirect={saveFormStateBeforeRedirect}
/>
)