summaryrefslogtreecommitdiff
path: root/frontend/src/App.tsx
diff options
context:
space:
mode:
authorblackhao <13851610112@163.com>2025-12-10 20:12:21 -0600
committerblackhao <13851610112@163.com>2025-12-10 20:12:21 -0600
commit9646da833bc3d94564c10649b62a378d0190471e (patch)
treed0c9c0584b8c4f167c281f5970f713b239a1d7c5 /frontend/src/App.tsx
parent9ba956c7aa601f0e6cd0fe2ede907cbc558fa1b8 (diff)
user data
Diffstat (limited to 'frontend/src/App.tsx')
-rw-r--r--frontend/src/App.tsx56
1 files changed, 54 insertions, 2 deletions
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 5477ff2..cfbb141 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -12,12 +12,14 @@ import ReactFlow, {
} from 'reactflow';
import 'reactflow/dist/style.css';
import useFlowStore from './store/flowStore';
+import { useAuthStore } from './store/authStore';
import LLMNode from './components/nodes/LLMNode';
import MergedEdge from './components/edges/MergedEdge';
import Sidebar from './components/Sidebar';
import LeftSidebar from './components/LeftSidebar';
import { ContextMenu } from './components/ContextMenu';
-import { Plus, Sun, Moon, LayoutGrid } from 'lucide-react';
+import { Plus, Sun, Moon, LayoutGrid, Loader2 } from 'lucide-react';
+import AuthPage from './pages/AuthPage';
const nodeTypes = {
llmNode: LLMNode,
@@ -397,10 +399,60 @@ function Flow() {
);
}
-export default function App() {
+function AuthWrapper() {
+ const { isAuthenticated, checkAuth, user } = useAuthStore();
+ const { refreshProjectTree, refreshFiles, loadArchivedNodes, clearBlueprint } = useFlowStore();
+ const [checking, setChecking] = useState(true);
+ const [initializing, setInitializing] = useState(false);
+ const prevUserRef = useRef<string | null>(null);
+
+ useEffect(() => {
+ checkAuth().finally(() => setChecking(false));
+ }, [checkAuth]);
+
+ // When user changes (login/logout), refresh all user-specific data
+ useEffect(() => {
+ const currentUsername = user?.username || null;
+
+ // If user changed, reload everything
+ if (isAuthenticated && currentUsername && currentUsername !== prevUserRef.current) {
+ setInitializing(true);
+ prevUserRef.current = currentUsername;
+
+ // Clear old data and load new user's data
+ clearBlueprint();
+ Promise.all([
+ refreshProjectTree(),
+ refreshFiles(),
+ loadArchivedNodes()
+ ]).finally(() => setInitializing(false));
+ } else if (!isAuthenticated) {
+ prevUserRef.current = null;
+ }
+ }, [isAuthenticated, user, refreshProjectTree, refreshFiles, loadArchivedNodes, clearBlueprint]);
+
+ if (checking || initializing) {
+ return (
+ <div className="min-h-screen flex items-center justify-center bg-gray-900">
+ <div className="flex flex-col items-center gap-4">
+ <Loader2 className="animate-spin text-blue-500" size={48} />
+ <p className="text-gray-400">{initializing ? 'Loading workspace...' : 'Loading...'}</p>
+ </div>
+ </div>
+ );
+ }
+
+ if (!isAuthenticated) {
+ return <AuthPage />;
+ }
+
return (
<ReactFlowProvider>
<Flow />
</ReactFlowProvider>
);
}
+
+export default function App() {
+ return <AuthWrapper />;
+}