Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix PostHog user identification persisting after signout (#40158)

Sean Oliver364f743054d3
diff --git a/apps/studio/lib/auth.tsx b/apps/studio/lib/auth.tsx
index fc40622efa6..7ac8442b23a 100644
--- a/apps/studio/lib/auth.tsx
+++ b/apps/studio/lib/auth.tsx
@@ -6,6 +6,7 @@ import {
AuthProvider as AuthProviderInternal,
clearLocalStorage,
gotrueClient,
+ posthogClient,
useAuthError,
} from 'common'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
@@ -45,6 +46,7 @@ export function useSignOut() {
return useCallback(async () => {
const result = await gotrueClient.signOut()
+ posthogClient.reset()
clearLocalStorage()
// Clear Assistant IndexedDB
await clearAssistantStorage()
diff --git a/packages/common/posthog-client.ts b/packages/common/posthog-client.ts
index b27e104efa3..1ce1a8f5ad9 100644
--- a/packages/common/posthog-client.ts
+++ b/packages/common/posthog-client.ts
@@ -142,6 +142,20 @@ class PostHogClient {
console.error('PostHog identify failed:', error)
}
}
+
+ reset() {
+ this.pendingIdentification = null
+ this.pendingGroups = {}
+ this.pendingEvents = []
+
+ if (!this.initialized) return
+
+ try {
+ posthog.reset()
+ } catch (error) {
+ console.error('PostHog reset failed:', error)
+ }
+ }
}
export const posthogClient = new PostHogClient()
diff --git a/packages/common/telemetry.tsx b/packages/common/telemetry.tsx
index 2a316aca010..64f77f1d503 100644
--- a/packages/common/telemetry.tsx
+++ b/packages/common/telemetry.tsx
@@ -17,6 +17,8 @@ import { TelemetryEvent } from './telemetry-constants'
import { getSharedTelemetryData } from './telemetry-utils'
import { posthogClient } from './posthog-client'
+export { posthogClient }
+
const { TELEMETRY_DATA } = LOCAL_STORAGE_KEYS
// Reexports GoogleTagManager with the right API key set