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 archived, 28 created_at, 29 permission_tokens!inner( 30 id, 31 root_entity, 32 permission_token_rights(*), 33 leaflets_in_publications(*, publications(*), documents(*)) 34 ) 35 ) 36 )`, 37 ) 38 .eq("identities.notifications.read", false) 39 .eq("id", auth_token) 40 .eq("confirmed", true) 41 .single() 42 : null; 43 if (!auth_res?.data?.identities) return null; 44 if (auth_res.data.identities.atp_did) { 45 //I should create a relationship table so I can do this in the above query 46 let { data: publications } = await supabaseServerClient 47 .from("publications") 48 .select("*") 49 .eq("identity_did", auth_res.data.identities.atp_did); 50 return { 51 ...auth_res.data.identities, 52 publications: publications || [], 53 }; 54 } 55 56 return { ...auth_res.data.identities, publications: [] }; 57}