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 validation when adding domains

+49 -14
+30 -12
actions/domains/addDomain.ts
··· 18 18 19 19 export async function addDomain(domain: string) { 20 20 let auth_token = cookies().get("auth_token")?.value; 21 - if (!auth_token) return null; 21 + if (!auth_token) return {}; 22 + 23 + try { 24 + await vercel.projects.addProjectDomain({ 25 + idOrName: "prj_9jX4tmYCISnm176frFxk07fF74kG", 26 + teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 27 + requestBody: { 28 + name: domain, 29 + }, 30 + }); 31 + } catch (e) { 32 + console.log(e); 33 + let error: "unknown-error" | "invalid_domain" | "domain_already_in_use" = 34 + "unknown-error"; 35 + if ((e as any).rawValue) { 36 + error = 37 + (e as { rawValue?: { error?: { code?: "invalid_domain" } } })?.rawValue 38 + ?.error?.code || "unknown-error"; 39 + } 40 + if ((e as any).body) { 41 + try { 42 + error = JSON.parse((e as any).body)?.error?.code || "unknown-error"; 43 + } catch (e) {} 44 + } 45 + 46 + return { error }; 47 + } 48 + 22 49 let { data: auth_data } = await supabase 23 50 .from("email_auth_tokens") 24 51 .select( ··· 31 58 .eq("id", auth_token) 32 59 .eq("confirmed", true) 33 60 .single(); 34 - if (!auth_data || !auth_data.email) return null; 61 + if (!auth_data || !auth_data.email) return {}; 35 62 36 63 await supabase.from("custom_domains").insert({ 37 64 domain, 38 65 identity: auth_data.email, 39 66 confirmed: false, 40 67 }); 41 - 42 - console.log( 43 - await vercel.projects.addProjectDomain({ 44 - idOrName: "prj_9jX4tmYCISnm176frFxk07fF74kG", 45 - teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 46 - requestBody: { 47 - name: domain, 48 - }, 49 - }), 50 - ); 68 + return {}; 51 69 }
+19 -2
components/ShareOptions/DomainOptions.tsx
··· 260 260 setDomainMenuState: (state: DomainMenuState) => void; 261 261 }) => { 262 262 let [value, setValue] = useState(""); 263 + let smoker = useSmoker(); 263 264 return ( 264 265 <div className="flex flex-col gap-1 px-3 py-1 max-w-full w-[600px]"> 265 266 <div> ··· 279 280 <ButtonPrimary 280 281 disabled={!value} 281 282 className="place-self-end mt-2" 282 - onMouseDown={async () => { 283 + onMouseDown={async (e) => { 283 284 // call the vercel api, set the thing... 284 - await addDomain(value); 285 + let { error } = await addDomain(value); 286 + if (error) { 287 + smoker({ 288 + error: true, 289 + text: 290 + error === "invalid_domain" 291 + ? "Invalid domain! Use just the base domain" 292 + : error === "domain_already_in_use" 293 + ? "That domain is already in use!" 294 + : "An unknown error occured", 295 + position: { 296 + y: e.clientY, 297 + x: e.clientX - 5, 298 + }, 299 + }); 300 + return; 301 + } 285 302 props.setDomainMenuState({ state: "domain-settings", domain: value }); 286 303 }} 287 304 >