Clear IndexedDB (#37495)

* clear indexeddb

* Fix dependency array

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
This commit is contained in:
Saxon FletcherandJoshen Lim authored and GitHub committed 2025-07-28 11:20:09 +10:00
1 parent 640eefdb30
commit 578b707e8b
2 files changed
+19 -1

No files matched your search

+5 -1
View File
@@ -8,6 +8,7 @@ import {
import { PropsWithChildren, useCallback, useEffect } from 'react'
import { toast } from 'sonner'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
import { GOTRUE_ERRORS, IS_PLATFORM } from './constants'
const AuthErrorToaster = ({ children }: PropsWithChildren) => {
@@ -42,12 +43,15 @@ export { useAuth, useIsLoggedIn, useSession, useUser } from 'common'
export function useSignOut() {
const queryClient = useQueryClient()
const { clearStorage: clearAssistantStorage } = useAiAssistantStateSnapshot()
return useCallback(async () => {
const result = await gotrueClient.signOut()
clearLocalStorage()
// Clear Assistant IndexedDB
await clearAssistantStorage()
await queryClient.clear()
return result
}, [queryClient])
}, [queryClient, clearAssistantStorage])
}
+14
View File
@@ -95,6 +95,15 @@ async function saveAiState(state: StoredAiAssistantState): Promise<void> {
}
}
async function clearStorage(): Promise<void> {
try {
const db = await openAiDb()
await db.clear(STORE_NAME)
} catch (error) {
console.error('Failed to clear AI state from IndexedDB:', error)
}
}
// Helper function to load state from IndexedDB
async function loadFromIndexedDB(projectRef: string): Promise<StoredAiAssistantState | null> {
try {
@@ -387,6 +396,10 @@ export const createAiAssistantState = (): AiAssistantState => {
}
}
},
clearStorage: async () => {
await clearStorage()
},
})
return state
@@ -413,6 +426,7 @@ export type AiAssistantState = AiAssistantData & {
clearSqlSnippets: () => void
getCachedSQLResults: (args: { messageId: string; snippetId?: string }) => any[] | undefined
loadPersistedState: (persistedState: StoredAiAssistantState) => void
clearStorage: () => Promise<void>
}
export const AiAssistantStateContext = createContext<AiAssistantState>(createAiAssistantState())