From e31380ed716d8c40750e441354c22f2a845ee864 Mon Sep 17 00:00:00 2001 From: Tom Smith <142233216+tomsmith8@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:14:17 +0100 Subject: [PATCH] Strip unused feature flags, fix isAdmin response parsing --- src/components/auth/auth-guard.tsx | 40 ++++++------------------------ src/lib/sphinx/types.ts | 6 ----- src/stores/feature-flag-store.ts | 36 --------------------------- 3 files changed, 7 insertions(+), 75 deletions(-) delete mode 100644 src/stores/feature-flag-store.ts diff --git a/src/components/auth/auth-guard.tsx b/src/components/auth/auth-guard.tsx index 76a0b784..b8b242f2 100644 --- a/src/components/auth/auth-guard.tsx +++ b/src/components/auth/auth-guard.tsx @@ -5,7 +5,6 @@ import { enable, isAndroid, getL402 } from "@/lib/sphinx" import type { IsAdminResponse } from "@/lib/sphinx" import { api } from "@/lib/api" import { useUserStore } from "@/stores/user-store" -import { useFeatureFlagStore } from "@/stores/feature-flag-store" import { useAppStore } from "@/stores/app-store" import { useMocks } from "@/lib/mock-data" @@ -13,7 +12,6 @@ export function AuthGuard({ children }: { children: React.ReactNode }) { const [unauthorized, setUnauthorized] = useState(false) const [loading, setLoading] = useState(true) const { setBudget, setIsAdmin, setPubKey, setIsAuthenticated } = useUserStore() - const setFlags = useFeatureFlagStore((s) => s.setFlags) const setGraphMeta = useAppStore((s) => s.setGraphMeta) const handleAuth = useCallback(async () => { @@ -25,7 +23,6 @@ export function AuthGuard({ children }: { children: React.ReactNode }) { await new Promise((r) => setTimeout(r, 5000)) } - // sphinx-bridge uses postMessage — works in Sphinx webview, no-ops in browser const result = await enable() if (result?.pubkey) { setPubKey(result.pubkey) @@ -34,7 +31,6 @@ export function AuthGuard({ children }: { children: React.ReactNode }) { setPubKey("") } - // Update budget from L402 balance const l402 = await getL402() if (!l402) { setBudget(0) @@ -53,29 +49,21 @@ export function AuthGuard({ children }: { children: React.ReactNode }) { const handleIsAdmin = useCallback(async () => { try { - const res = await api.get("/isAdmin") + const res = await api.get<{ data: IsAdminResponse }>("/isAdmin") + const d = res.data - if (!res.isPublic && !res.isAdmin && !res.isMember) { + if (!d.isPublic && !d.isAdmin && !d.isMember) { setUnauthorized(true) return } - setIsAdmin(!!res.isAdmin) - localStorage.setItem("admin", JSON.stringify({ isAdmin: res.isAdmin })) - - setFlags({ - trendingTopics: res.trendingTopics, - queuedSources: res.queuedSources, - customSchema: res.customSchema, - realtimeGraph: res.realtimeGraph ?? false, - chatInterface: res.chatInterface ?? false, - }) - + setIsAdmin(!!d.isAdmin) + localStorage.setItem("admin", JSON.stringify({ isAdmin: d.isAdmin })) setIsAuthenticated(true) } catch { setIsAuthenticated(true) } - }, [setIsAdmin, setFlags, setIsAuthenticated]) + }, [setIsAdmin, setIsAuthenticated]) const fetchGraphMeta = useCallback(async () => { try { @@ -92,34 +80,20 @@ export function AuthGuard({ children }: { children: React.ReactNode }) { useEffect(() => { const init = async () => { if (useMocks()) { - // Dev mode: skip real auth, set admin + all flags setIsAdmin(true) setIsAuthenticated(true) setBudget(5000) - setFlags({ - trendingTopics: true, - queuedSources: true, - customSchema: true, - realtimeGraph: true, - chatInterface: true, - addItem: true, - addContent: true, - settings: true, - }) setGraphMeta("Dev Graph", "Local development instance") setLoading(false) return } - // Always try sphinx-bridge enable — it uses postMessage internally. - // In Sphinx webview: succeeds and sets isSphinx=true - // In plain browser: times out silently and sets isSphinx=false await handleAuth() await Promise.all([handleIsAdmin(), fetchGraphMeta()]) setLoading(false) } init() - }, [handleAuth, handleIsAdmin, fetchGraphMeta, setIsAdmin, setIsAuthenticated, setBudget, setFlags, setGraphMeta]) + }, [handleAuth, handleIsAdmin, fetchGraphMeta, setIsAdmin, setIsAuthenticated, setBudget, setGraphMeta]) if (loading) { return ( diff --git a/src/lib/sphinx/types.ts b/src/lib/sphinx/types.ts index 068825fc..dac86d23 100644 --- a/src/lib/sphinx/types.ts +++ b/src/lib/sphinx/types.ts @@ -2,12 +2,6 @@ export interface IsAdminResponse { isAdmin: boolean isPublic: boolean isMember: boolean - trendingTopics: boolean - queuedSources: boolean - customSchema: boolean - realtimeGraph: boolean - chatInterface: boolean - swarmUiUrl?: string } export interface SignedMessage { diff --git a/src/stores/feature-flag-store.ts b/src/stores/feature-flag-store.ts deleted file mode 100644 index 6438a0a9..00000000 --- a/src/stores/feature-flag-store.ts +++ /dev/null @@ -1,36 +0,0 @@ -"use client" - -import { create } from "zustand" - -interface FeatureFlags { - trendingTopics: boolean - queuedSources: boolean - customSchema: boolean - realtimeGraph: boolean - chatInterface: boolean - addItem: boolean - addContent: boolean - settings: boolean -} - -interface FeatureFlagActions { - setFlags: (flags: Partial) => void -} - -export type FeatureFlagStore = FeatureFlags & FeatureFlagActions - -const defaults: FeatureFlags = { - trendingTopics: false, - queuedSources: false, - customSchema: false, - realtimeGraph: false, - chatInterface: false, - addItem: false, - addContent: false, - settings: false, -} - -export const useFeatureFlagStore = create((set) => ({ - ...defaults, - setFlags: (flags) => set((s) => ({ ...s, ...flags })), -}))