diff --git a/actions/getIdentityData.ts b/actions/getIdentityData.ts index 62953125..a9084596 100644 --- a/actions/getIdentityData.ts +++ b/actions/getIdentityData.ts @@ -1,21 +1,15 @@ "use server"; import { IdResolver } from "@atproto/identity"; -import { createServerClient } from "@supabase/ssr"; import { cookies } from "next/headers"; -import { Database } from "supabase/database.types"; +import { supabaseServerClient } from "supabase/serverClient"; -let supabase = createServerClient( - process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, - process.env.SUPABASE_SERVICE_ROLE_KEY as string, - { cookies: {} }, -); let idResolver = new IdResolver(); export async function getIdentityData() { let cookieStore = await cookies(); let auth_token = cookieStore.get("auth_token")?.value; let auth_res = auth_token - ? await supabase + ? await supabaseServerClient .from("email_auth_tokens") .select( `*, @@ -34,7 +28,7 @@ export async function getIdentityData() { if (!auth_res?.data?.identities) return null; if (auth_res.data.identities.atp_did) { //I should create a relationship table so I can do this in the above query - let { data: publications } = await supabase + let { data: publications } = await supabaseServerClient .from("publications") .select("*") .eq("identity_did", auth_res.data.identities.atp_did); diff --git a/app/home/LeafletList.tsx b/app/home/LeafletList.tsx index e322176f..45533755 100644 --- a/app/home/LeafletList.tsx +++ b/app/home/LeafletList.tsx @@ -58,6 +58,7 @@ export function LeafletList(props: {
{leaflets.map((leaflet, index) => ( ( - process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, - process.env.SUPABASE_SERVICE_ROLE_KEY as string, - { cookies: {} }, -); export default async function Home() { let cookieStore = await cookies(); @@ -52,7 +46,7 @@ export default async function Home() { let permission_token = auth_res?.home_leaflet; if (!permission_token) { - let res = await supabase + let res = await supabaseServerClient .from("identities") .select( `*, @@ -66,7 +60,7 @@ export default async function Home() { if (!permission_token) return
no home page wierdly
; let [homeLeafletFacts, allLeafletFacts] = await Promise.all([ - supabase.rpc("get_facts", { + supabaseServerClient.rpc("get_facts", { root: permission_token.root_entity, }), auth_res @@ -76,7 +70,7 @@ export default async function Home() { (r) => r.permission_tokens.root_entity, ), }, - { supabase }, + { supabase: supabaseServerClient }, ) : undefined, ]); diff --git a/src/replicache/attributes.ts b/src/replicache/attributes.ts index 558f130c..4dee9b7c 100644 --- a/src/replicache/attributes.ts +++ b/src/replicache/attributes.ts @@ -1,9 +1,5 @@ -import { AppBskyFeedGetPostThread } from "@atproto/api"; -import { - PostView, - ThreadViewPost, -} from "@atproto/api/dist/client/types/app/bsky/feed/defs"; -import { DeepAsReadonlyJSONValue } from "./utils"; +import type { AppBskyFeedGetPostThread } from "@atproto/api"; +import type { DeepAsReadonlyJSONValue } from "./utils"; const RootAttributes = { "root/page": { diff --git a/src/replicache/index.tsx b/src/replicache/index.tsx index 480ae9ab..84c245f9 100644 --- a/src/replicache/index.tsx +++ b/src/replicache/index.tsx @@ -24,6 +24,7 @@ import { callRPC } from "app/api/rpc/client"; import { UndoManager } from "@rocicorp/undo"; import { addShortcut } from "src/shortcuts"; import { createUndoManager } from "src/undoManager"; +import { RealtimeChannel } from "@supabase/supabase-js"; export type Fact = { id: string; @@ -69,6 +70,7 @@ export function ReplicacheProvider(props: { name: string; children: React.ReactNode; initialFactsOnly?: boolean; + disablePull?: boolean; }) { let [rep, setRep] = useState>(null); let [undoManager] = useState(createUndoManager()); @@ -103,6 +105,7 @@ export function ReplicacheProvider(props: { if (props.initialFactsOnly) return; let supabase = supabaseBrowserClient(); let newRep = new Replicache({ + pullInterval: props.disablePull ? null : undefined, pushDelay: 500, mutators: Object.fromEntries( Object.keys(mutations).map((m) => { @@ -158,16 +161,19 @@ export function ReplicacheProvider(props: { }, }); setRep(newRep); - let channel = supabase.channel(`rootEntity:${props.name}`); + let channel: RealtimeChannel | null = null; + if (!props.disablePull) { + channel = supabase.channel(`rootEntity:${props.name}`); - channel.on("broadcast", { event: "poke" }, () => { - newRep.pull(); - }); - channel.subscribe(); + channel.on("broadcast", { event: "poke" }, () => { + newRep.pull(); + }); + channel.subscribe(); + } return () => { newRep.close(); setRep(null); - channel.unsubscribe(); + channel?.unsubscribe(); }; }, [props.name, props.initialFactsOnly, props.token]); return ( diff --git a/supabase/serverClient.ts b/supabase/serverClient.ts index d9f98ca3..0ebc9cfe 100644 --- a/supabase/serverClient.ts +++ b/supabase/serverClient.ts @@ -1,5 +1,5 @@ import { createClient } from "@supabase/supabase-js"; -import { Database } from "supabase/database.types"; +import type { Database } from "supabase/database.types"; export const supabaseServerClient = createClient( process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, process.env.SUPABASE_SERVICE_ROLE_KEY as string,