mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Clear IndexedDB (#37495)
* clear indexeddb * Fix dependency array --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
This commit is contained in:
1 parent
640eefdb30
commit
578b707e8b
2 files changed
+19
-1
No files matched your search
@@ -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])
|
||||
}
|
||||
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user