import { useEffect, useState } from 'react'; import { useNavigate } from '@remix-run/react'; import { ClientOnly } from 'remix-utils/client-only'; import { useStore } from '@nanostores/react'; import { authStore } from '~/lib/stores/auth'; import { BaseChat } from '~/components/chat/BaseChat'; import { Chat } from '~/components/chat/Chat.client'; import { Header } from '~/components/header/Header'; import BackgroundRays from '~/components/ui/BackgroundRays'; import { motion } from 'framer-motion'; import { UserMenu } from '~/components/header/UserMenu'; /** * Authenticated chat component that ensures user is logged in */ export function AuthenticatedChat() { const navigate = useNavigate(); const authState = useStore(authStore); const [isInitialized, setIsInitialized] = useState(false); useEffect(() => { // Check authentication status after component mounts const checkAuth = async () => { // Give auth store time to initialize await new Promise((resolve) => setTimeout(resolve, 100)); const state = authStore.get(); if (!state.loading) { if (!state.isAuthenticated) { navigate('/auth'); } else { setIsInitialized(true); } } }; checkAuth(); }, [navigate]); useEffect(() => { // Subscribe to auth changes const unsubscribe = authStore.subscribe((state) => { if (!state.loading && !state.isAuthenticated) { navigate('/auth'); } }); return () => { unsubscribe(); }; }, [navigate]); // Show loading state if (authState.loading || !isInitialized) { return (

Initializing workspace...

); } // If not authenticated, don't render (will redirect) if (!authState.isAuthenticated) { return null; } // Render authenticated content with enhanced header return (
}>{() => }
); }