feat(platform): 开源发布 - 初始化 Open AI Canvas

This commit is contained in:
ddCat
2026-07-22 14:18:14 +08:00
commit aea35896eb
365 changed files with 66410 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import type { ReactNode } from "react";
import { useEffect } from "react";
import { applyUserSession } from "@/lib/user-session";
import { getAuthSession } from "@/services/api/auth";
import { FullScreenLoader } from "@/components/ui/aceternity/full-screen-loader";
import { useUserStore } from "@/stores/use-user-store";
export function AuthSessionHydrator({ children }: { children: ReactNode }) {
const hydrated = useUserStore((state) => state.hydrated);
useEffect(() => {
let cancelled = false;
getAuthSession()
.then(async (payload) => {
if (!cancelled) await applyUserSession(payload);
})
.catch(async () => {
if (!cancelled) await applyUserSession({ user: null, systemChannels: [] });
});
return () => {
cancelled = true;
};
}, []);
return hydrated ? children : <FullScreenLoader />;
}

View File

@@ -0,0 +1,15 @@
import type { ReactNode } from "react";
import { Navigate, useLocation } from "react-router";
import { FullScreenLoader } from "@/components/ui/aceternity/full-screen-loader";
import { useUserStore } from "@/stores/use-user-store";
export function RequireAuth({ children }: { children: ReactNode }) {
const location = useLocation();
const hydrated = useUserStore((state) => state.hydrated);
const user = useUserStore((state) => state.user);
if (!hydrated) return <FullScreenLoader />;
if (!user) return <Navigate to={`/login?next=${encodeURIComponent(location.pathname + location.search)}`} replace />;
return children;
}