MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / ProfileContextProvider

Function ProfileContextProvider

components/contextManagers/profile.tsx:29–117  ·  view source on GitHub ↗
(props: {
  children: JSX.Element;
  supabase: ReturnType<typeof createClient<Database>>;
})

Source from the content-addressed store, hash-verified

27});
28
29export function ProfileContextProvider(props: {
30 children: JSX.Element;
31 supabase: ReturnType<typeof createClient<Database>>;
32}) {
33 const [profile, setProfile] = useState<ProfilesRow | null | undefined>(
34 undefined,
35 );
36 const [pathname, setPathname] = useState<string | null>(null);
37 const session = useSession();
38 const router = useRouter();
39
40 const refreshProfile = useCallback(
41 async (localSession?: Session): Promise<ProfilesRow | undefined> => {
42 localSession = localSession || (session ?? undefined);
43 if (!localSession || !props.supabase || !setProfile) return;
44 const { data, error } = await props.supabase
45 .from("profiles")
46 .select("*, organizations(*, is_paid(*), finetuned_models(*))")
47 .single();
48 if (error) {
49 console.error(error.message);
50 await props.supabase.auth.signOut();
51 await router.push("/sign-in");
52 return;
53 }
54 let newProfile: ProfilesRow | null;
55
56 // Refresh onboarding steps
57 if (data?.org_id) {
58 // Have actions?
59 const { count: actionCount } = await props.supabase
60 .from("actions")
61 .select("*", { count: "exact", head: true })
62 .eq("org_id", data.org_id);
63 console.log("action", actionCount);
64 // Have API endpoint?
65 const { count: apiWithHostSetCount } = await props.supabase
66 .from("apis")
67 .select("*", { count: "exact", head: true })
68 .eq("org_id", data.org_id)
69 .neq("api_host", "");
70 console.log("api", apiWithHostSetCount);
71 // >0 conversations (used playground)
72 const { count: conversationsCount } = await props.supabase
73 .from("conversations")
74 .select("*", { count: "exact", head: true })
75 .eq("org_id", data.org_id);
76 console.log("conversation", conversationsCount);
77 // Usage num queries >0 (used API)
78 const { count: usageCount } = await props.supabase
79 .from("usage")
80 .select("*", { count: "exact", head: true })
81 .eq("org_id", data.org_id)
82 .gt("num_user_queries", 0);
83 console.log("usage", usageCount);
84
85 newProfile = {
86 ...data,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected