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.

chore(frontend): move the oauth client into lib/utils (#126843)

Paul D'Ambracce08a1475f9
diff --git a/frontend/bin/layer-baseline.txt b/frontend/bin/layer-baseline.txt
index 6a139b5e92f4..db480cfec77e 100644
--- a/frontend/bin/layer-baseline.txt
+++ b/frontend/bin/layer-baseline.txt
@@ -113,7 +113,6 @@ frontend/src/layout/today/todayWorkItems.ts -> products/tasks/frontend/spaces/ta
frontend/src/lib/api.ts -> frontend/src/exporter/exporterViewLogic.ts
frontend/src/lib/api.ts -> frontend/src/lib/apiRequestTiming.ts
frontend/src/lib/api.ts -> frontend/src/lib/logic/apiStatusLogic.ts
-frontend/src/lib/api.ts -> frontend/src/lib/oauth/oauthClient.ts
frontend/src/lib/api.ts -> frontend/src/queries/utils.ts
frontend/src/lib/api.ts -> frontend/src/scenes/surveys/constants.tsx
frontend/src/lib/components/Account/AccountMenu.tsx -> frontend/src/scenes/billing/billingLogic.tsx
@@ -458,7 +457,6 @@ frontend/src/lib/ui/ContextMenu/ContextMenu.tsx -> frontend/src/lib/components/S
frontend/src/lib/ui/DropdownMenu/DropdownMenu.tsx -> frontend/src/lib/components/ScrollableShadows/ScrollableShadows.tsx
frontend/src/lib/ui/SelectPrimitive/SelectPrimitive.tsx -> frontend/src/lib/components/ScrollableShadows/ScrollableShadows.tsx
frontend/src/lib/utils/accessControlUtils.ts -> frontend/src/scenes/sceneTypes.ts
-frontend/src/lib/utils/apiHost.ts -> frontend/src/lib/oauth/oauthClient.ts
frontend/src/lib/utils/dateFilters.ts -> frontend/src/lib/components/DateFilter/types.ts
frontend/src/lib/utils/deleteWithUndo.tsx -> frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsx
frontend/src/lib/utils/deleteWithUndo.tsx -> frontend/src/scenes/dashboard/liveDashboardIds.ts
@@ -469,7 +467,6 @@ frontend/src/lib/utils/eventUsageLogic.ts -> frontend/src/scenes/userLogic.ts
frontend/src/lib/utils/eventUsageLogic.ts -> products/business_intelligence/frontend/biEditorAnalytics.ts
frontend/src/lib/utils/eventUsageLogic.ts -> products/experiments/frontend/experimentStatus.ts
frontend/src/lib/utils/events.ts -> frontend/src/taxonomy/taxonomy.tsx
-frontend/src/lib/utils/getAppContext.ts -> frontend/src/lib/oauth/oauthClient.ts
frontend/src/loadPostHogJS.tsx -> products/webmcp/frontend/webmcpToolError.ts
frontend/src/models/cohortsModel.ts -> frontend/src/exporter/exporterViewLogic.ts
frontend/src/models/cohortsModel.ts -> frontend/src/scenes/cohorts/CohortFilters/constants.tsx
diff --git a/frontend/src/lib/api.test.ts b/frontend/src/lib/api.test.ts
index f3f635deb9a9..c506bf6a23b9 100644
--- a/frontend/src/lib/api.test.ts
+++ b/frontend/src/lib/api.test.ts
@@ -4,12 +4,12 @@ import posthog from 'posthog-js'
import api, { ApiConfig, ApiError, ApiRequest, NetworkError, ResponseBodyReadError } from 'lib/api'
import { shouldReportApiFailure } from 'lib/api-error'
import { apiStatusLogic } from 'lib/logic/apiStatusLogic'
-import * as oauthClient from 'lib/oauth/oauthClient'
+import * as oauthClient from 'lib/utils/oauthClient'
import { NodeKind } from '~/queries/schema/schema-general'
import { PropertyFilterType, PropertyOperator } from '~/types'
-// Mirrors SESSION_KEY in lib/oauth/oauthClient — the localStorage key its real getStoredSession reads.
+// Mirrors SESSION_KEY in lib/utils/oauthClient — the localStorage key its real getStoredSession reads.
const OAUTH_SESSION_KEY = 'ph_oauth_session'
describe('API helper', () => {
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index 63cdde18d2f8..68d37e942d8d 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -19,7 +19,7 @@ import { ApiRequestTiming, ApiRequestTimingRecorder } from 'lib/apiRequestTiming
import { ActivityLogProps } from 'lib/components/ActivityLog/ActivityLog'
import { ActivityLogItem } from 'lib/components/ActivityLog/humanizeActivity'
import { apiStatusLogic, awaitReauthentication, isUserActionInProgress } from 'lib/logic/apiStatusLogic'
-import { getBackendHost, getStoredSession, isOAuthMode, refreshAccessToken } from 'lib/oauth/oauthClient'
+import { getBackendHost, getStoredSession, isOAuthMode, refreshAccessToken } from 'lib/utils/oauthClient'
import { objectClean } from 'lib/utils/objects'
import { toParams } from 'lib/utils/url'
import { CohortCalculationHistoryResponse } from 'scenes/cohorts/cohortCalculationHistorySceneLogic'
diff --git a/frontend/src/lib/components/DebugNotice.tsx b/frontend/src/lib/components/DebugNotice.tsx
index 5958ba7d2a94..e033550e3284 100644
--- a/frontend/src/lib/components/DebugNotice.tsx
+++ b/frontend/src/lib/components/DebugNotice.tsx
@@ -7,8 +7,8 @@ import { Link, Tooltip } from '@posthog/lemon-ui'
import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { IconBranch } from 'lib/lemon-ui/icons'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
-import { getRegionForHost, getStoredSession, OAUTH_REGIONS } from 'lib/oauth/oauthClient'
import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
+import { getRegionForHost, getStoredSession, OAUTH_REGIONS } from 'lib/utils/oauthClient'
export interface DebugNoticeProps {
isCollapsed?: boolean
diff --git a/frontend/src/lib/oauth/oauthLogic.ts b/frontend/src/lib/oauth/oauthLogic.ts
index 5e5893346b3a..5a5c7edea5ce 100644
--- a/frontend/src/lib/oauth/oauthLogic.ts
+++ b/frontend/src/lib/oauth/oauthLogic.ts
@@ -2,15 +2,20 @@ import { MakeLogicType, actions, kea, listeners, path, reducers } from 'kea'
import { urlToAction } from 'kea-router'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import {
+ buildAuthorizeUrl,
+ clearSession,
+ exchangeCodeForToken,
+ OAUTH_REGIONS,
+ PendingAuth,
+} from 'lib/utils/oauthClient'
+import { generateCodeVerifier, generateState } from 'lib/utils/pkce'
import { getRelativeNextPath } from 'lib/utils/url'
import { Region } from '~/types'
import { clearSQLEditorDrafts } from 'products/data_warehouse/frontend/sqlEditorDraftCleanup'
-import { buildAuthorizeUrl, clearSession, exchangeCodeForToken, OAUTH_REGIONS, PendingAuth } from './oauthClient'
-import { generateCodeVerifier, generateState } from './pkce'
-
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface oauthLogicValues {
loginError: string | null
diff --git a/frontend/src/lib/utils/apiHost.ts b/frontend/src/lib/utils/apiHost.ts
index c594aea0ca5a..3a536b26c4a7 100644
--- a/frontend/src/lib/utils/apiHost.ts
+++ b/frontend/src/lib/utils/apiHost.ts
@@ -1,4 +1,4 @@
-import { getBackendHost } from 'lib/oauth/oauthClient'
+import { getBackendHost } from 'lib/utils/oauthClient'
import { inStorybook, inStorybookTestRunner } from './dom'
import { getAppContext } from './getAppContext'
diff --git a/frontend/src/lib/utils/getAppContext.ts b/frontend/src/lib/utils/getAppContext.ts
index 502f010e1bed..99c481b6bb0a 100644
--- a/frontend/src/lib/utils/getAppContext.ts
+++ b/frontend/src/lib/utils/getAppContext.ts
@@ -1,4 +1,4 @@
-import { getOAuthContextIds, isOAuthMode } from 'lib/oauth/oauthClient'
+import { getOAuthContextIds, isOAuthMode } from 'lib/utils/oauthClient'
import { AppContext, OrganizationType, PathType, TeamType, UserType } from '~/types'
diff --git a/frontend/src/lib/oauth/oauthClient.ts b/frontend/src/lib/utils/oauthClient.ts
similarity index 100%
rename from frontend/src/lib/oauth/oauthClient.ts
rename to frontend/src/lib/utils/oauthClient.ts
diff --git a/frontend/src/lib/oauth/pkce.ts b/frontend/src/lib/utils/pkce.ts
similarity index 100%
rename from frontend/src/lib/oauth/pkce.ts
rename to frontend/src/lib/utils/pkce.ts
diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx
index 292305d3e236..99b3f3c69f67 100644
--- a/frontend/src/loadPostHogJS.tsx
+++ b/frontend/src/loadPostHogJS.tsx
@@ -1,7 +1,6 @@
import posthog, { BeforeSendFn, PostHogConfig } from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
-import { isOAuthMode } from 'lib/oauth/oauthClient'
import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'
import { isEmbeddedPageFrame } from 'lib/utils/embeddedPageFrame'
import {
@@ -12,6 +11,7 @@ import {
} from 'lib/utils/exceptionFilters'
import { getAppContext, isHobbyDeployment } from 'lib/utils/getAppContext'
import { redactMetricVariableUrls } from 'lib/utils/metricVariableUrlRedaction'
+import { isOAuthMode } from 'lib/utils/oauthClient'
import { identifyInstanceInPostHog, identifyUserInPostHog } from 'lib/utils/posthogIdentity'
import { dropWebMCPToolErrors } from 'products/webmcp/frontend/webmcpToolError'
diff --git a/frontend/src/scenes/authentication/shared/authScene/DevLoginPanel.tsx b/frontend/src/scenes/authentication/shared/authScene/DevLoginPanel.tsx
index 1e5f27b328f7..69cda826e232 100644
--- a/frontend/src/scenes/authentication/shared/authScene/DevLoginPanel.tsx
+++ b/frontend/src/scenes/authentication/shared/authScene/DevLoginPanel.tsx
@@ -8,8 +8,8 @@ import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { Lettermark } from 'lib/lemon-ui/Lettermark'
import { Spinner } from 'lib/lemon-ui/Spinner'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { OAUTH_REGIONS } from 'lib/oauth/oauthClient'
import { oauthLogic } from 'lib/oauth/oauthLogic'
+import { OAUTH_REGIONS } from 'lib/utils/oauthClient'
import { hashCodeForString } from 'lib/utils/strings'
import { Region } from '~/types'
diff --git a/frontend/src/scenes/userLogic.ts b/frontend/src/scenes/userLogic.ts
index ab9fe3684f8c..ee4c9fc2e709 100644
--- a/frontend/src/scenes/userLogic.ts
+++ b/frontend/src/scenes/userLogic.ts
@@ -9,8 +9,8 @@ import api, { ApiConfig, getCookie } from 'lib/api'
import { DashboardCompatibleScenes } from 'lib/components/SceneDashboardChoice/sceneDashboardChoiceModalLogic'
// eslint-disable-next-line import/no-cycle
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
-import { clearSession, isOAuthMode, setOAuthContextIds } from 'lib/oauth/oauthClient'
import { getAppContext } from 'lib/utils/getAppContext'
+import { clearSession, isOAuthMode, setOAuthContextIds } from 'lib/utils/oauthClient'
import { identifyUserInPostHog } from 'lib/utils/posthogIdentity'
import { clearPendingVerificationEmail } from 'scenes/authentication/shared/verificationCode'
diff --git a/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts
index 13681ceca71d..77ac43c54162 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts
@@ -4,8 +4,8 @@ import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
import posthog from 'posthog-js'
-import { setOAuthContextIds } from 'lib/oauth/oauthClient'
import { getCurrentTeamIdOrNone, getCurrentUserIdOrNone } from 'lib/utils/getAppContext'
+import { setOAuthContextIds } from 'lib/utils/oauthClient'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
diff --git a/products/mcp_analytics/frontend/emptyState/mcpAnalyticsSetupLogic.ts b/products/mcp_analytics/frontend/emptyState/mcpAnalyticsSetupLogic.ts
index f7d879340bad..5cf4cb1852cd 100644
--- a/products/mcp_analytics/frontend/emptyState/mcpAnalyticsSetupLogic.ts
+++ b/products/mcp_analytics/frontend/emptyState/mcpAnalyticsSetupLogic.ts
@@ -1,6 +1,6 @@
import { MakeLogicType, actions, connect, kea, path, reducers, selectors } from 'kea'
-import { getBackendHost } from 'lib/oauth/oauthClient'
+import { getBackendHost } from 'lib/utils/oauthClient'
import { teamLogic } from 'scenes/teamLogic'
import type { TeamType } from '~/types'