a tool for shared writing and social publishing
at main 46 lines 1.1 kB view raw
1"use server"; 2 3import { drizzle } from "drizzle-orm/node-postgres"; 4import { and, eq } from "drizzle-orm"; 5import postgres from "postgres"; 6import { 7 phone_number_auth_tokens, 8 phone_rsvps_to_entity, 9} from "drizzle/schema"; 10import { cookies } from "next/headers"; 11import { Database } from "supabase/database.types"; 12import { pool } from "supabase/pool"; 13 14export async function getPhoneRSVPToEventState(entityId: string) { 15 const token = (await cookies()).get("phone_auth_token"); 16 17 if (!token) { 18 return null; 19 } 20 21 const client = await pool.connect(); 22 const db = drizzle(client); 23 24 const [authToken] = await db 25 .select() 26 .from(phone_number_auth_tokens) 27 .where(eq(phone_number_auth_tokens.id, token.value)); 28 29 if (!authToken || !authToken.confirmed) { 30 client.release(); 31 return null; 32 } 33 34 const [rsvp] = await db 35 .select() 36 .from(phone_rsvps_to_entity) 37 .where( 38 and( 39 eq(phone_rsvps_to_entity.phone_number, authToken.phone_number), 40 eq(phone_rsvps_to_entity.entity, entityId), 41 ), 42 ); 43 44 client.release(); 45 return rsvp; 46}