a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add removing domain

+67 -14
+48
actions/domains/deleteDomain.ts
··· 1 + "use server"; 2 + import { cookies } from "next/headers"; 3 + import { Database } from "supabase/database.types"; 4 + import { createServerClient } from "@supabase/ssr"; 5 + import { Vercel } from "@vercel/sdk"; 6 + 7 + let supabase = createServerClient<Database>( 8 + process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, 9 + process.env.SUPABASE_SERVICE_ROLE_KEY as string, 10 + { cookies: {} }, 11 + ); 12 + 13 + const VERCEL_TOKEN = process.env.VERCEL_TOKEN; 14 + const vercel = new Vercel({ 15 + bearerToken: VERCEL_TOKEN, 16 + }); 17 + export async function deleteDomain({ domain }: { domain: string }) { 18 + let auth_token = cookies().get("auth_token")?.value; 19 + if (!auth_token) return null; 20 + let { data: auth_data } = await supabase 21 + .from("email_auth_tokens") 22 + .select( 23 + `*, 24 + identities( 25 + *, 26 + custom_domains(*) 27 + )`, 28 + ) 29 + .eq("id", auth_token) 30 + .eq("confirmed", true) 31 + .single(); 32 + if ( 33 + !auth_data || 34 + !auth_data.email || 35 + !auth_data.identities?.custom_domains.find((d) => d.domain === domain) 36 + ) 37 + return null; 38 + 39 + await supabase.from("custom_domain_routes").delete().eq("domain", domain); 40 + await supabase.from("custom_domains").delete().eq("domain", domain); 41 + await vercel.projects.removeProjectDomain({ 42 + idOrName: "prj_9jX4tmYCISnm176frFxk07fF74kG", 43 + teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 44 + domain, 45 + }); 46 + 47 + return true; 48 + }
+15 -12
app/api/rpc/[command]/domain_routes.ts
··· 8 8 domain: z.string(), 9 9 }), 10 10 handler: async ({ domain }, { vercel }: Pick<Env, "vercel">) => { 11 - let [status, config] = await Promise.all([ 12 - vercel.domains.getDomain({ 13 - domain, 14 - teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 15 - }), 16 - vercel.domains.getDomainConfig({ 17 - domain, 18 - teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 19 - }), 20 - ]); 21 - 22 - return { status, config }; 11 + try { 12 + let [status, config] = await Promise.all([ 13 + vercel.domains.getDomain({ 14 + domain, 15 + teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 16 + }), 17 + vercel.domains.getDomainConfig({ 18 + domain, 19 + teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 20 + }), 21 + ]); 22 + return { status, config }; 23 + } catch (e) { 24 + return { error: true }; 25 + } 23 26 }, 24 27 }); 25 28
+4 -2
components/ShareOptions/DomainOptions.tsx
··· 12 12 import { usePublishLink } from "."; 13 13 import { addDomainPath } from "actions/domains/addDomainPath"; 14 14 import { useReplicache } from "src/replicache"; 15 + import { deleteDomain } from "actions/domains/deleteDomain"; 15 16 16 17 type DomainMenuState = 17 18 | { ··· 188 189 let { data } = useSWR(props.domain, async (domain) => { 189 190 return await callRPC("get_domain_status", { domain }); 190 191 }); 191 - let pending = data?.config.misconfigured; 192 + let pending = data?.config?.misconfigured || data?.error; 192 193 return ( 193 194 <label htmlFor={props.domain}> 194 195 <input ··· 365 366 <div className="flex gap-3 justify-between items-center mt-2"> 366 367 <button 367 368 className="text-accent-contrast font-bold " 368 - onMouseDown={() => { 369 + onMouseDown={async () => { 370 + await deleteDomain({ domain: props.domain }); 369 371 props.setDomainMenuState({ state: "default" }); 370 372 }} 371 373 >