Skip to content

Commit 578b707

Browse files
SaxonFjoshenlim
andauthored
Clear IndexedDB (supabase#37495)
* clear indexeddb * Fix dependency array --------- Co-authored-by: Joshen Lim <[email protected]>
1 parent 640eefd commit 578b707

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

apps/studio/lib/auth.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { PropsWithChildren, useCallback, useEffect } from 'react'
99
import { toast } from 'sonner'
1010

11+
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
1112
import { GOTRUE_ERRORS, IS_PLATFORM } from './constants'
1213

1314
const AuthErrorToaster = ({ children }: PropsWithChildren) => {
@@ -42,12 +43,15 @@ export { useAuth, useIsLoggedIn, useSession, useUser } from 'common'
4243

4344
export function useSignOut() {
4445
const queryClient = useQueryClient()
46+
const { clearStorage: clearAssistantStorage } = useAiAssistantStateSnapshot()
4547

4648
return useCallback(async () => {
4749
const result = await gotrueClient.signOut()
4850
clearLocalStorage()
51+
// Clear Assistant IndexedDB
52+
await clearAssistantStorage()
4953
await queryClient.clear()
5054

5155
return result
52-
}, [queryClient])
56+
}, [queryClient, clearAssistantStorage])
5357
}

apps/studio/state/ai-assistant-state.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ async function saveAiState(state: StoredAiAssistantState): Promise<void> {
9595
}
9696
}
9797

98+
async function clearStorage(): Promise<void> {
99+
try {
100+
const db = await openAiDb()
101+
await db.clear(STORE_NAME)
102+
} catch (error) {
103+
console.error('Failed to clear AI state from IndexedDB:', error)
104+
}
105+
}
106+
98107
// Helper function to load state from IndexedDB
99108
async function loadFromIndexedDB(projectRef: string): Promise<StoredAiAssistantState | null> {
100109
try {
@@ -387,6 +396,10 @@ export const createAiAssistantState = (): AiAssistantState => {
387396
}
388397
}
389398
},
399+
400+
clearStorage: async () => {
401+
await clearStorage()
402+
},
390403
})
391404

392405
return state
@@ -413,6 +426,7 @@ export type AiAssistantState = AiAssistantData & {
413426
clearSqlSnippets: () => void
414427
getCachedSQLResults: (args: { messageId: string; snippetId?: string }) => any[] | undefined
415428
loadPersistedState: (persistedState: StoredAiAssistantState) => void
429+
clearStorage: () => Promise<void>
416430
}
417431

418432
export const AiAssistantStateContext = createContext<AiAssistantState>(createAiAssistantState())

0 commit comments

Comments
 (0)