Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/studio/lib/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 changes: 14 additions & 0 deletions apps/studio/state/ai-assistant-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -387,6 +396,10 @@ export const createAiAssistantState = (): AiAssistantState => {
}
}
},

clearStorage: async () => {
await clearStorage()
},
})

return state
Expand All @@ -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())
Expand Down
Loading