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
9 changes: 0 additions & 9 deletions web-app/src/providers/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,61 @@
* Initializes the auth service and sets up event listeners
*/

import { useCallback, useEffect, useState, ReactNode } from 'react'
import { PlatformFeature } from '@/lib/platform/types'
import { PlatformFeatures } from '@/lib/platform/const'
import { initializeAuthStore, getAuthStore } from '@/hooks/useAuth'
import { useThreads } from '@/hooks/useThreads'
import { useMessages } from '@/hooks/useMessages'
import { usePrompt } from '@/hooks/usePrompt'
import { useAppState } from '@/hooks/useAppState'
import { useNavigate } from '@tanstack/react-router'
import { useServiceHub } from '@/hooks/useServiceHub'

Check warning on line 15 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

6-15 lines are not covered with tests

interface AuthProviderProps {
children: ReactNode
}

export function AuthProvider({ children }: AuthProviderProps) {
const [isReady, setIsReady] = useState(false)
const navigate = useNavigate()
const serviceHub = useServiceHub()

Check warning on line 24 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

21-24 lines are not covered with tests

// Check if authentication is enabled for this platform
const isAuthenticationEnabled =
PlatformFeatures[PlatformFeature.AUTHENTICATION]

Check warning on line 28 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

27-28 lines are not covered with tests

// Fetch user data when user logs in
const fetchUserData = useCallback(async () => {
try {
const { setThreads } = useThreads.getState()

Check warning on line 33 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

31-33 lines are not covered with tests
const { setMessages } = useMessages.getState()

// Fetch threads first
const threads = await serviceHub.threads().fetchThreads()
setThreads(threads)

// Fetch messages for each thread
const messagePromises = threads.map(async (thread) => {
const messages = await serviceHub.messages().fetchMessages(thread.id)
setMessages(thread.id, messages)
})

await Promise.all(messagePromises)
} catch (error) {
console.error('Failed to fetch user data:', error)
}
}, [serviceHub])

Check warning on line 41 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

36-41 lines are not covered with tests

// Reset all app data when user logs out
const resetAppData = useCallback(() => {

Check warning on line 44 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

44 line is not covered with tests
// Clear all threads (including favorites)
const { clearAllThreads, setCurrentThreadId } = useThreads.getState()
clearAllThreads()
setCurrentThreadId(undefined)

Check warning on line 48 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

46-48 lines are not covered with tests

// Clear all messages
const { clearAllMessages } = useMessages.getState()
clearAllMessages()

Check warning on line 52 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

51-52 lines are not covered with tests

// Reset prompt
const { resetPrompt } = usePrompt.getState()
resetPrompt()

Check warning on line 56 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

55-56 lines are not covered with tests

// Clear app state (streaming, tokens, errors, etc.)
const { clearAppState } = useAppState.getState()
clearAppState()

Check warning on line 60 in web-app/src/providers/AuthProvider.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

59-60 lines are not covered with tests

// Navigate back to home to ensure clean state
navigate({ to: '/', replace: true })
Expand Down
10 changes: 1 addition & 9 deletions web-app/src/providers/DataProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMessages } from '@/hooks/useMessages'
import { useModelProvider } from '@/hooks/useModelProvider'

import { useAppUpdater } from '@/hooks/useAppUpdater'
Expand All @@ -19,7 +18,6 @@ export function DataProvider() {
const { setProviders, selectedModel, selectedProvider, getProviderByName } =
useModelProvider()

const { setMessages } = useMessages()
const { checkForUpdate } = useAppUpdater()
const { setServers } = useMCPServers()
const { setAssistants, initializeWithLastUsed } = useAssistant()
Expand Down Expand Up @@ -85,14 +83,8 @@ export function DataProvider() {
.fetchThreads()
.then((threads) => {
setThreads(threads)
threads.forEach((thread) =>
serviceHub
.messages()
.fetchMessages(thread.id)
.then((messages) => setMessages(thread.id, messages))
)
})
}, [serviceHub, setThreads, setMessages])
}, [serviceHub, setThreads])

// Check for app updates
useEffect(() => {
Expand Down
Loading