ruvector/studio/lib/auth.tsx
rUv 814f595995 feat(studio): Add complete RuVector Studio application
Major additions:
- Complete Next.js studio application with 1600+ components
- Docker support (Dockerfile.combined, docker-compose.yml)
- GCP deployment documentation and benchmarks
- SQL benchmark scripts for performance testing
- Sentry integration for monitoring
- Comprehensive test suite and mocks

Studio features:
- Dashboard and admin interfaces
- Data visualization components
- Authentication and user management
- API integration with RuVector backend
- Static data and public assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:04:48 +00:00

57 lines
1.6 KiB
TypeScript

import { useQueryClient } from '@tanstack/react-query'
import { PropsWithChildren, useCallback, useEffect } from 'react'
import { toast } from 'sonner'
import {
AuthProvider as AuthProviderInternal,
clearLocalStorage,
gotrueClient,
posthogClient,
useAuthError,
} from 'common'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
import { GOTRUE_ERRORS, IS_PLATFORM } from './constants'
const AuthErrorToaster = ({ children }: PropsWithChildren) => {
const error = useAuthError()
useEffect(() => {
if (error !== null) {
// Check for unverified GitHub users after a GitHub sign in
if (error.message === GOTRUE_ERRORS.UNVERIFIED_GITHUB_USER) {
toast.error(
'Please verify your email on GitHub first, then reach out to us at support@supabase.io to log into the dashboard'
)
return
}
toast.error(error.message)
}
}, [error])
return children
}
export const AuthProvider = ({ children }: PropsWithChildren) => {
return (
<AuthProviderInternal alwaysLoggedIn={!IS_PLATFORM}>
<AuthErrorToaster>{children}</AuthErrorToaster>
</AuthProviderInternal>
)
}
export function useSignOut() {
const queryClient = useQueryClient()
const { clearStorage: clearAssistantStorage } = useAiAssistantStateSnapshot()
return useCallback(async () => {
const result = await gotrueClient.signOut()
posthogClient.reset()
clearLocalStorage()
// Clear Assistant IndexedDB
await clearAssistantStorage()
queryClient.clear()
return result
}, [queryClient, clearAssistantStorage])
}