a tool for shared writing and social publishing
1"use server"; 2 3import { cookies } from "next/headers"; 4import { supabaseServerClient } from "supabase/serverClient"; 5import { cache } from "react"; 6export const getIdentityData = cache(uncachedGetIdentityData); 7export async function uncachedGetIdentityData() { 8 let cookieStore = await cookies(); 9 let auth_token = 10 cookieStore.get("auth_token")?.value || 11 cookieStore.get("external_auth_token")?.value; 12 let auth_res = auth_token 13 ? await supabaseServerClient 14 .from("email_auth_tokens") 15 .select( 16 `*, 17 identities( 18 *, 19 bsky_profiles(*), 20 notifications(count), 21 publication_subscriptions(*), 22 custom_domains!custom_domains_identity_id_fkey(publication_domains(*), *), 23 home_leaflet:permission_tokens!identities_home_page_fkey(*, permission_token_rights(*, 24 entity_sets(entities(facts(*))) 25 )), 26 permission_token_on_homepage( 27 created_at, 28 permission_tokens!inner( 29 id, 30 root_entity, 31 permission_token_rights(*), 32 leaflets_in_publications(*, publications(*), documents(*)) 33 ) 34 ) 35 )`, 36 ) 37 .eq("identities.notifications.read", false) 38 .eq("id", auth_token) 39 .eq("confirmed", true) 40 .single() 41 : null; 42 if (!auth_res?.data?.identities) return null; 43 if (auth_res.data.identities.atp_did) { 44 //I should create a relationship table so I can do this in the above query 45 let { data: publications } = await supabaseServerClient 46 .from("publications") 47 .select("*") 48 .eq("identity_did", auth_res.data.identities.atp_did); 49 return { 50 ...auth_res.data.identities, 51 publications: publications || [], 52 }; 53 } 54 55 return { ...auth_res.data.identities, publications: [] }; 56}