Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(www): add project ID field to compute waitlist (#51772)

Anad1a38675ea2e
diff --git a/apps/www/app/(products)/compute/_components/WaitlistForm.tsx b/apps/www/app/(products)/compute/_components/WaitlistForm.tsx
index c1e1bbc030f..f87f4a44df2 100644
--- a/apps/www/app/(products)/compute/_components/WaitlistForm.tsx
+++ b/apps/www/app/(products)/compute/_components/WaitlistForm.tsx
@@ -1,5 +1,6 @@
'use client'
+import { parseProjectRef } from '~/lib/compute-project-ref'
import { CircleAlert } from 'lucide-react'
import Link from 'next/link'
import { useEffect, useState } from 'react'
@@ -15,6 +16,7 @@ import {
Separator,
TextArea,
} from 'ui'
+import { InfoTooltip } from 'ui-patterns/info-tooltip'
import { Alert } from 'ui/src/components/shadcn/ui/alert'
interface FormData {
@@ -22,6 +24,7 @@ interface FormData {
lastName: string
email: string
company: string
+ projectRef: string
useCase: string
details: string
}
@@ -31,6 +34,7 @@ const defaultFormValue: FormData = {
lastName: '',
email: '',
company: '',
+ projectRef: '',
useCase: '',
details: '',
}
@@ -64,6 +68,8 @@ export function WaitlistForm() {
if (!formData.lastName) newErrors.lastName = 'This field is required'
if (!formData.email) newErrors.email = 'This field is required'
else if (!isValidEmail(formData.email)) newErrors.email = 'Invalid email address'
+ if (formData.projectRef.trim() && !parseProjectRef(formData.projectRef))
+ newErrors.projectRef = 'Invalid project ID'
setErrors(newErrors)
return Object.keys(newErrors).length === 0
}
@@ -85,7 +91,11 @@ export function WaitlistForm() {
const response = await fetch('/api-v2/submit-form-compute-waitlist', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ ...formData, honeypot }),
+ body: JSON.stringify({
+ ...formData,
+ projectRef: parseProjectRef(formData.projectRef),
+ honeypot,
+ }),
})
if (response.ok) {
@@ -129,13 +139,16 @@ export function WaitlistForm() {
>
First name
{errors.firstName && (
- <span className="text-foreground-muted text-xs">{errors.firstName}</span>
+ <span className="text-foreground-muted text-xs leading-3">
+ {errors.firstName}
+ </span>
)}
</Label>
<Input
id="firstName"
name="firstName"
value={formData.firstName}
+ className={errors.firstName ? 'border-destructive!' : ''}
onChange={handleChange}
placeholder="Jane"
/>
@@ -147,13 +160,14 @@ export function WaitlistForm() {
>
Last name
{errors.lastName && (
- <span className="text-foreground-muted text-xs">{errors.lastName}</span>
+ <span className="text-foreground-muted text-xs leading-3">{errors.lastName}</span>
)}
</Label>
<Input
id="lastName"
name="lastName"
value={formData.lastName}
+ className={errors.lastName ? 'border-destructive!' : ''}
onChange={handleChange}
placeholder="Doe"
/>
@@ -163,7 +177,7 @@ export function WaitlistForm() {
<Label htmlFor="email" className="text-foreground-light flex justify-between text-left">
Work email
{errors.email && (
- <span className="text-foreground-muted text-xs">{errors.email}</span>
+ <span className="text-foreground-muted text-xs leading-3">{errors.email}</span>
)}
</Label>
<Input
@@ -171,6 +185,7 @@ export function WaitlistForm() {
name="email"
type="email"
value={formData.email}
+ className={errors.email ? 'border-destructive!' : ''}
onChange={handleChange}
placeholder="[email protected]"
/>
@@ -187,6 +202,47 @@ export function WaitlistForm() {
placeholder="Company name"
/>
</div>
+ <div className="flex flex-col gap-2">
+ <div className="w-full flex gap-2 justify-between text-left">
+ <Label
+ htmlFor="projectRef"
+ className="text-foreground-light flex items-center gap-1.5 text-left"
+ >
+ <span>Project ID</span>
+ <InfoTooltip className="max-w-[450px] text-foreground-light text-pretty">
+ <p>
+ The 20-letter ID in your project URL: https://
+ <span className="text-foreground">your-project-ref</span>.supabase.co (shown as
+ Project ID in{' '}
+ <a
+ className="hover:text-foreground underline"
+ target="_blank"
+ rel="noreferrer"
+ href="https://supabase.com/dashboard/project/_/settings/general"
+ >
+ Settings → General
+ </a>
+ )
+ </p>
+ </InfoTooltip>
+ </Label>
+ {errors.projectRef && (
+ <span className="text-foreground-muted text-xs leading-3">{errors.projectRef}</span>
+ )}
+ </div>
+ <Input
+ id="projectRef"
+ name="projectRef"
+ value={formData.projectRef}
+ className={errors.projectRef ? 'border-destructive!' : ''}
+ onChange={handleChange}
+ placeholder="abcdefghijklmnopqrst"
+ aria-describedby="projectRef-description"
+ />
+ <p id="projectRef-description" className="text-foreground-lighter text-xs">
+ Only projects created in us-west-2 can access Compute during private alpha.
+ </p>
+ </div>
<div className="flex flex-col gap-2">
<Label htmlFor="useCase" className="text-foreground-light text-left">
What will you run on Compute?
@@ -216,6 +272,7 @@ export function WaitlistForm() {
onChange={handleChange}
placeholder="What are you building, and what would you run on Compute?"
rows={3}
+ className={errors.details ? 'border-destructive!' : ''}
/>
</div>
diff --git a/apps/www/app/api-v2/submit-form-compute-waitlist/route.tsx b/apps/www/app/api-v2/submit-form-compute-waitlist/route.tsx
index b7bd004a0cb..6b885b3fc74 100644
--- a/apps/www/app/api-v2/submit-form-compute-waitlist/route.tsx
+++ b/apps/www/app/api-v2/submit-form-compute-waitlist/route.tsx
@@ -1,4 +1,5 @@
import * as Sentry from '@sentry/nextjs'
+import { parseProjectRef } from '~/lib/compute-project-ref'
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
@@ -72,7 +73,7 @@ export async function POST(req: Request) {
})
}
- const { firstName, lastName, email, company, useCase, details, honeypot } = body
+ const { firstName, lastName, email, company, projectRef, useCase, details, honeypot } = body
// Anti-spam honeypot: real users never fill this hidden field.
if (honeypot) {
@@ -116,6 +117,18 @@ export async function POST(req: Request) {
})
}
+ const parsedProjectRef =
+ typeof projectRef === 'string' && projectRef.length <= MAX_FIELD_LENGTH
+ ? parseProjectRef(projectRef)
+ : null
+
+ if (projectRef && !parsedProjectRef) {
+ return new Response(JSON.stringify({ message: 'Invalid project ID' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 422,
+ })
+ }
+
try {
if (!HUBSPOT_PORTAL_ID || !HUBSPOT_FORM_GUID) {
throw new Error('HubSpot credentials not configured')
@@ -126,6 +139,9 @@ export async function POST(req: Request) {
{ objectTypeId: '0-1', name: 'lastname', value: lastName },
{ objectTypeId: '0-1', name: 'email', value: email },
...(company ? [{ objectTypeId: '0-1', name: 'company', value: company }] : []),
+ ...(parsedProjectRef
+ ? [{ objectTypeId: '0-1', name: 'supabase_project_ref', value: parsedProjectRef }]
+ : []),
...(useCase ? [{ objectTypeId: '0-1', name: 'compute_use_case', value: useCase }] : []),
...(details ? [{ objectTypeId: '0-1', name: 'message', value: details }] : []),
]
diff --git a/apps/www/lib/compute-project-ref.test.ts b/apps/www/lib/compute-project-ref.test.ts
new file mode 100644
index 00000000000..17c677fafeb
--- /dev/null
+++ b/apps/www/lib/compute-project-ref.test.ts
@@ -0,0 +1,36 @@
+import { describe, expect, it } from 'vitest'
+
+import { parseProjectRef } from './compute-project-ref'
+
+const REF = 'abcdefghijklmnopqrst'
+
+describe('parseProjectRef', () => {
+ it.each([
+ REF,
+ ` ${REF.toUpperCase()} `,
+ `https://${REF}.supabase.co`,
+ `https://${REF}.supabase.co/`,
+ `${REF}.supabase.co/rest/v1/`,
+ `db.${REF}.supabase.co`,
+ `https://${REF}.functions.supabase.co/hello`,
+ `https://app.supabase.com/project/${REF}`,
+ `https://supabase.com/dashboard/project/${REF}`,
+ `https://supabase.com/dashboard/project/${REF}/settings/general`,
+ `supabase.com/dashboard/project/${REF}?tab=api`,
+ ])('extracts the ref from %s', (input) => {
+ expect(parseProjectRef(input)).toBe(REF)
+ })
+
+ it.each([
+ '',
+ 'abc',
+ `${REF}x`,
+ `https://${REF}.supabase.com`,
+ `https://${REF}.example.co`,
+ `https://evil.com/${REF}.supabase.co`,
+ `https://${REF}.supabase.co.evil.com`,
+ 'https://supabase.com/dashboard/projects',
+ ])('rejects %s', (input) => {
+ expect(parseProjectRef(input)).toBeNull()
+ })
+})
diff --git a/apps/www/lib/compute-project-ref.ts b/apps/www/lib/compute-project-ref.ts
new file mode 100644
index 00000000000..83e7b6ca2b5
--- /dev/null
+++ b/apps/www/lib/compute-project-ref.ts
@@ -0,0 +1,17 @@
+const REF_PATTERN = /^[a-z]{20}$/
+const PROJECT_HOST_PATTERN =
+ /^(?:https?:\/\/)?(?:db\.)?([a-z]{20})(?:\.functions)?\.supabase\.co(?:[/?#:].*)?$/
+const DASHBOARD_URL_PATTERN =
+ /^(?:https?:\/\/)?(?:www\.|app\.)?supabase\.com\/(?:dashboard\/)?project\/([a-z]{20})(?:[/?#].*)?$/
+
+/**
+ * Accepts a bare project ref, a project URL (https://<ref>.supabase.co, plus the
+ * db. and .functions hosts), or a dashboard URL
+ * (https://supabase.com/dashboard/project/<ref>) and returns the ref, or null if
+ * the input matches none of them.
+ */
+export function parseProjectRef(input: string): string | null {
+ const value = input.trim().toLowerCase()
+ if (REF_PATTERN.test(value)) return value
+ return value.match(PROJECT_HOST_PATTERN)?.[1] ?? value.match(DASHBOARD_URL_PATTERN)?.[1] ?? null
+}