Skip to content

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

feat(mgmt-api): adds partner confirmation page (#43237)

Raúl Barroso86ef5e11cc6d
diff --git a/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx b/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
index b69e049afc5..8b5203f133e 100644
--- a/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
+++ b/apps/studio/components/interfaces/Database/Migrations/Migrations.tsx
@@ -72,7 +72,7 @@ const Migrations = () => {
Try refreshing your browser, but if the issue persists for more than a few
minutes, please reach out to us via support.
</p>
- <p className="mb-4">Error: {(error as any)?.message ?? 'Unknown'}</p>
+ <p className="mb-4">Error: {error?.message ?? 'Unknown'}</p>
</>
}
>
diff --git a/apps/studio/data/branches/branch-diff-query.ts b/apps/studio/data/branches/branch-diff-query.ts
index 14f26c8a5d8..b531fadd106 100644
--- a/apps/studio/data/branches/branch-diff-query.ts
+++ b/apps/studio/data/branches/branch-diff-query.ts
@@ -1,8 +1,8 @@
import { useQuery } from '@tanstack/react-query'
-
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError, UseCustomQueryOptions } from 'types'
+
import { branchKeys } from './keys'
export type BranchDiffVariables = {
@@ -24,7 +24,10 @@ export async function getBranchDiff({
const { data: diffData, error } = await get('/v1/branches/{branch_id_or_ref}/diff', {
params: {
path: { branch_id_or_ref: branchRef },
- query: Object.keys(query).length > 0 ? query : undefined,
+ query:
+ Object.keys(query).length > 0
+ ? (query as { included_schemas?: string; pgdelta?: boolean })
+ : undefined,
},
headers: {
Accept: 'text/plain',
diff --git a/apps/studio/data/organizations/organization-available-regions-query.ts b/apps/studio/data/organizations/organization-available-regions-query.ts
index 594880ec61e..a07be137b65 100644
--- a/apps/studio/data/organizations/organization-available-regions-query.ts
+++ b/apps/studio/data/organizations/organization-available-regions-query.ts
@@ -1,12 +1,12 @@
import { useQuery } from '@tanstack/react-query'
-
import type { operations } from 'api-types'
import { get, handleError } from 'data/fetchers'
import type { ResponseError, UseCustomQueryOptions } from 'types'
+
import { organizationKeys } from './keys'
export type DesiredInstanceSizeForAvailableRegions =
- operations['v1-get-available-regions']['parameters']['query']['desired_instance_size']
+ operations['ProjectsController_getRegions']['parameters']['query']['desired_instance_size']
export type OrganizationAvailableRegionsVariables = {
slug?: string
diff --git a/apps/studio/data/partners/keys.ts b/apps/studio/data/partners/keys.ts
new file mode 100644
index 00000000000..e0811d3dacc
--- /dev/null
+++ b/apps/studio/data/partners/keys.ts
@@ -0,0 +1,3 @@
+export const stripeProductKeys = {
+ get: (arId: string | undefined) => ['stripe', 'product', arId] as const,
+}
diff --git a/apps/studio/data/partners/stripe-product-confirm-mutation.ts b/apps/studio/data/partners/stripe-product-confirm-mutation.ts
new file mode 100644
index 00000000000..463059c11b2
--- /dev/null
+++ b/apps/studio/data/partners/stripe-product-confirm-mutation.ts
@@ -0,0 +1,53 @@
+import { useMutation } from '@tanstack/react-query'
+import { toast } from 'sonner'
+
+import { handleError, post } from '@/data/fetchers'
+import type { ResponseError, UseCustomMutationOptions } from '@/types'
+
+type ConfirmAccountRequestVariables = {
+ arId: string
+}
+
+async function confirmAccountRequest({ arId }: ConfirmAccountRequestVariables) {
+ if (!arId) throw new Error('Account request ID is required')
+
+ const { data, error } = await post(
+ '/platform/stripe/product/provisioning/account_requests/{id}/confirm',
+ {
+ params: { path: { id: arId } },
+ }
+ )
+
+ if (error) handleError(error)
+ return data
+}
+
+type ConfirmAccountRequestData = Awaited<ReturnType<typeof confirmAccountRequest>>
+
+export const useConfirmAccountRequestMutation = ({
+ onSuccess,
+ onError,
+ ...options
+}: Omit<
+ UseCustomMutationOptions<
+ ConfirmAccountRequestData,
+ ResponseError,
+ ConfirmAccountRequestVariables
+ >,
+ 'mutationFn'
+> = {}) => {
+ return useMutation({
+ mutationFn: (vars) => confirmAccountRequest(vars),
+ async onSuccess(data, variables, context) {
+ await onSuccess?.(data, variables, context)
+ },
+ async onError(data, variables, context) {
+ if (onError === undefined) {
+ toast.error(`Failed to confirm account request: ${data.message}`)
+ } else {
+ onError(data, variables, context)
+ }
+ },
+ ...options,
+ })
+}
diff --git a/apps/studio/data/partners/stripe-product-query.ts b/apps/studio/data/partners/stripe-product-query.ts
new file mode 100644
index 00000000000..1293692c48c
--- /dev/null
+++ b/apps/studio/data/partners/stripe-product-query.ts
@@ -0,0 +1,34 @@
+import { queryOptions } from '@tanstack/react-query'
+import type { components } from 'api-types'
+
+import { get, handleError } from '../fetchers'
+import { stripeProductKeys } from './keys'
+
+type GetAccountRequestVariables = {
+ arId?: string
+}
+
+export type AccountRequestDetails = components['schemas']['AccountRequestDetailsDto']
+
+async function getAccountRequest({ arId }: GetAccountRequestVariables, signal?: AbortSignal) {
+ if (!arId) throw new Error('Account request ID is required')
+
+ const { data, error } = await get('/platform/stripe/product/provisioning/account_requests/{id}', {
+ params: { path: { id: arId } },
+ signal,
+ })
+
+ if (error) handleError(error)
+ return data
+}
+
+export const accountRequestQueryOptions = (
+ { arId }: GetAccountRequestVariables,
+ { enabled = true }: { enabled?: boolean } = { enabled: true }
+) => {
+ return queryOptions({
+ queryKey: stripeProductKeys.get(arId),
+ queryFn: ({ signal }) => getAccountRequest({ arId }, signal),
+ enabled: enabled && typeof arId !== 'undefined',
+ })
+}
diff --git a/apps/studio/pages/partners/stripe/product/login.tsx b/apps/studio/pages/partners/stripe/product/login.tsx
new file mode 100644
index 00000000000..ba30f36f457
--- /dev/null
+++ b/apps/studio/pages/partners/stripe/product/login.tsx
@@ -0,0 +1,121 @@
+import { useQuery } from '@tanstack/react-query'
+import { useParams } from 'common'
+import { useRouter } from 'next/router'
+import { useEffect } from 'react'
+import {
+ Alert_Shadcn_,
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Button,
+ LogoLoader,
+ WarningIcon,
+} from 'ui'
+
+import APIAuthorizationLayout from '@/components/layouts/APIAuthorizationLayout'
+import { useConfirmAccountRequestMutation } from '@/data/partners/stripe-product-confirm-mutation'
+import { accountRequestQueryOptions } from '@/data/partners/stripe-product-query'
+import { withAuth } from '@/hooks/misc/withAuth'
+import { useSignOut } from '@/lib/auth'
+
+const StripeProductLoginPage = () => {
+ const router = useRouter()
+ const { ar_id } = useParams()
+
+ const signOut = useSignOut()
+
+ const {
+ data: accountRequest,
+ isPending,
+ isSuccess,
+ isError,
+ error,
+ } = useQuery(accountRequestQueryOptions({ arId: ar_id }))
+
+ const {
+ mutateAsync: confirmAccountRequest,
+ isPending: isConfirming,
+ isSuccess: isConfirmed,
+ } = useConfirmAccountRequestMutation()
+
+ useEffect(() => {
+ if (!router.isReady) return
+
+ if (!ar_id) {
+ router.push('/404')
+ return
+ }
+ }, [router.isReady, ar_id, router])
+
+ const handleApprove = async () => {
+ if (!ar_id) return
+
+ confirmAccountRequest({ arId: ar_id })
+ // The onSuccess handler in the mutation will show a success screen, on error it'll show a toast, so we don't need
+ // to do anything else here
+ }
+
+ return (
+ <APIAuthorizationLayout>
+ <div className="flex flex-col items-center justify-center h-full">
+ {isConfirming ? (
+ <>
+ <LogoLoader />
+ <p className="pt-4 text-foreground-light">Setting up your organization...</p>
+ </>
+ ) : isConfirmed ? (
+ <>
+ <h2 className="py-2 text-lg font-medium">Organization Created</h2>
+ <p className="text-foreground-light">
+ Your Supabase organization has been linked successfully.
+ </p>
+ <p className="pt-4 text-sm text-foreground-lighter">You can close this window.</p>
+ </>
+ ) : isPending ? (
+ <LogoLoader />
+ ) : isSuccess ? (
+ <>
+ <h2 className="py-2 text-lg font-medium">Stripe Product Account Request</h2>
+ <p className="text-center text-foreground-light">
+ Stripe Product wants to create a Supabase organization for{' '}
+ <strong>{accountRequest.email}</strong>
+ {accountRequest.name && <> ({accountRequest.name})</>}.
+ </p>
+ {(accountRequest as any).email_matches ? (
+ <div className="py-6">
+ <Button size="large" type="primary" onClick={handleApprove}>
+ Approve
+ </Button>
+ </div>
+ ) : (
+ <>
+ <Alert_Shadcn_ variant="warning" className="mt-4">
+ <WarningIcon />
+ <AlertTitle_Shadcn_>Wrong account</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ You need to be logged in as <strong>{accountRequest.email}</strong> to approve
+ this request.
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ <div className="py-6">
+ <Button size="large" type="default" onClick={() => signOut()}>
+ Sign out
+ </Button>
+ </div>
+ </>
+ )}
+ <p className="text-sm text-foreground-lighter text-center">
+ This will create a new Supabase organization linked to your Stripe account.
+ </p>
+ </>
+ ) : isError ? (
+ <>
+ <h2 className="py-2 text-lg font-medium text-destructive">Error</h2>
+ <p className="text-foreground-light">{error?.message}</p>
+ </>
+ ) : null}
+ </div>
+ </APIAuthorizationLayout>
+ )
+}
+
+export default withAuth(StripeProductLoginPage)
diff --git a/packages/api-types/types/api.d.ts b/packages/api-types/types/api.d.ts
index abfa94b31da..8a91d9d3f0b 100644
--- a/packages/api-types/types/api.d.ts
+++ b/packages/api-types/types/api.d.ts
@@ -2092,6 +2092,8 @@ export interface components {
}
AuthConfigResponse: {
api_max_request_duration: number | null
+ custom_oauth_enabled: boolean
+ custom_oauth_max_providers: number
db_max_pool_size: number | null
/** @enum {string|null} */
db_max_pool_size_unit: 'connections' | 'percent' | null
@@ -3837,6 +3839,7 @@ export interface components {
}
UpdateAuthConfigBody: {
api_max_request_duration?: number | null
+ custom_oauth_enabled?: boolean
db_max_pool_size?: number | null
/** @enum {string|null} */
db_max_pool_size_unit?: 'connections' | 'percent' | null
@@ -4365,9 +4368,12 @@ export interface components {
V1CreateProjectBody: {
/** @description Database password */
db_pass: string
- /** @enum {string} */
+ /**
+ * @description Desired instance size. Omit this field to always default to the smallest possible size.
+ * @example nano
+ * @enum {string}
+ */
desired_instance_size?:
- | 'pico'
| 'nano'
| 'micro'
| 'small'
@@ -4407,15 +4413,10 @@ export interface components {
* @enum {string}
*/
plan?: 'free' | 'pro'
- /**
- * @deprecated
- * @description Postgres engine version. If not provided, the latest version will be used.
- * @enum {string}
- */
- postgres_engine?: '15' | '17' | '17-oriole'
/**
* @deprecated
* @description Region you want your server to reside in. Use region_selection instead.
+ * @example us-east-1
* @enum {string}
*/
region?:
@@ -4479,12 +4480,6 @@ export interface components {
/** @enum {string} */
type: 'smartGroup'
}
- /**
- * @deprecated
- * @description Release channel. If not provided, GA will be used.
- * @enum {string}
- */
- release_channel?: 'internal' | 'alpha' | 'beta' | 'ga' | 'withdrawn' | 'preview'
/**
* Format: uri
* @description Template URL used to create the project from the CLI.
@@ -5008,7 +5003,8 @@ export interface operations {
parameters: {
query?: {
included_schemas?: string
- pgdelta?: string
+ /** @description Use pg-delta instead of Migra for diffing when true */
+ pgdelta?: boolean
}
header?: never
path: {
@@ -12313,9 +12309,8 @@ export interface operations {
query: {
/** @description Continent code to determine regional recommendations: NA (North America), SA (South America), EU (Europe), AF (Africa), AS (Asia), OC (Oceania), AN (Antarctica) */
continent?: 'NA' | 'SA' | 'EU' | 'AF' | 'AS' | 'OC' | 'AN'
- /** @description Desired instance size */
+ /** @description Desired instance size. Omit this field to always default to the smallest possible size. */
desired_instance_size?:
- | 'pico'
| 'nano'
| 'micro'
| 'small'
diff --git a/packages/api-types/types/platform.d.ts b/packages/api-types/types/platform.d.ts
index 2915887577f..87dcbcbf936 100644
--- a/packages/api-types/types/platform.d.ts
+++ b/packages/api-types/types/platform.d.ts
@@ -4337,6 +4337,40 @@ export interface paths {
patch?: never
trace?: never
}
+ '/platform/stripe/product/provisioning/account_requests/{id}': {
+ parameters: {
+ query?: never
+ header?: never
+ path?: never
+ cookie?: never
+ }
+ /** Get account request details */
+ get: operations['AccountRequestsController_getAccountRequest']
+ put?: never
+ post?: never
+ delete?: never
+ options?: never
+ head?: never
+ patch?: never
+ trace?: never
+ }
+ '/platform/stripe/product/provisioning/account_requests/{id}/confirm': {
+ parameters: {
+ query?: never
+ header?: never
+ path?: never
+ cookie?: never
+ }
+ get?: never
+ put?: never
+ /** Confirm account request (from Studio) */
+ post: operations['AccountRequestsController_confirmAccountRequest']
+ delete?: never
+ options?: never
+ head?: never
+ patch?: never
+ trace?: never
+ }
'/platform/stripe/setup-intent': {
parameters: {
query?: never
@@ -4609,6 +4643,23 @@ export interface components {
scope?: 'V0'
token_alias: string
}
+ AccountRequestDetailsDto: {
+ email: string
+ email_matches: boolean
+ expires_at: string
+ id: string
+ name?: string
+ orchestrator: {
+ stripe?: {
+ account: string
+ organization?: string
+ }
+ type: string
+ }
+ scopes?: string[]
+ /** @enum {string} */
+ status: 'pending' | 'complete' | 'expired'
+ }
AddAwsAccountToPrivateLinkBody: {
account_name?: string
aws_account_id: string
@@ -4790,6 +4841,10 @@ export interface components {
payment_intent_id: string
size?: string
}
+ ConfirmResponseDto: {
+ organization_slug: string
+ success: boolean
+ }
ConfirmSubscriptionChangeBody: {
payment_intent_id: string
}
@@ -5148,7 +5203,12 @@ export interface components {
| {
billing_email: string | null
/** @enum {string|null} */
- billing_partner: 'fly' | 'aws_marketplace' | 'vercel_marketplace' | null
+ billing_partner:
+ | 'fly'
+ | 'aws_marketplace'
+ | 'vercel_marketplace'
+ | 'stripe_product'
+ | null
id: number
is_owner: boolean
name: string
@@ -5200,8 +5260,6 @@ export interface components {
db_sql?: string
/** @enum {string} */
desired_instance_size?:
- | 'pico'
- | 'nano'
| 'micro'
| 'small'
| 'medium'
@@ -5226,7 +5284,7 @@ export interface components {
* @description Postgres engine version. If not provided, the latest version will be used.
* @enum {string}
*/
- postgres_engine?: '13' | '14' | '15' | '17' | '17-oriole'
+ postgres_engine?: '15' | '17' | '17-oriole'
/** @description Provider region selection. Only one of db_region or region_selection can be specified. */
region_selection?:
| {
@@ -6499,7 +6557,7 @@ export interface components {
}[]
billing_cycle_anchor: number
/** @enum {string} */
- billing_partner?: 'fly' | 'aws_marketplace' | 'vercel_marketplace'
+ billing_partner?: 'fly' | 'aws_marketplace' | 'vercel_marketplace' | 'stripe_product'
billing_via_partner: boolean
current_period_end: number
current_period_start: number
@@ -6703,6 +6761,8 @@ export interface components {
GoTrueConfigResponse: {
API_MAX_REQUEST_DURATION: number | null
AUDIT_LOG_DISABLE_POSTGRES: boolean | null
+ CUSTOM_OAUTH_ENABLED: boolean
+ CUSTOM_OAUTH_MAX_PROVIDERS: number
DB_MAX_POOL_SIZE: number | null
/** @enum {string|null} */
DB_MAX_POOL_SIZE_UNIT: 'connections' | 'percent' | null
@@ -7143,7 +7203,9 @@ export interface components {
| 'auth.user_sessions'
| 'auth.leaked_password_protection'
| 'auth.advanced_auth_settings'
+ | 'auth.performance_settings'
| 'backup.retention_days'
+ | 'backup.restore_to_new_project'
| 'function.max_count'
| 'function.size_limit_mb'
| 'realtime.max_concurrent_users'
@@ -7158,6 +7220,7 @@ export interface components {
| 'project_pausing'
| 'project_cloning'
| 'assistant.advance_model'
+ | 'integrations.github_connections'
/** @enum {string} */
type: 'boolean' | 'numeric' | 'set'
}
@@ -7505,7 +7568,7 @@ export interface components {
OrganizationResponse: {
billing_email: string | null
/** @enum {string|null} */
- billing_partner: 'fly' | 'aws_marketplace' | 'vercel_marketplace' | null
+ billing_partner: 'fly' | 'aws_marketplace' | 'vercel_marketplace' | 'stripe_product' | null
id: number
is_owner: boolean
name: string
@@ -7568,7 +7631,7 @@ export interface components {
OrganizationSlugResponse: {
billing_email: string | null
/** @enum {string|null} */
- billing_partner: 'fly' | 'aws_marketplace' | 'vercel_marketplace' | null
+ billing_partner: 'fly' | 'aws_marketplace' | 'vercel_marketplace' | 'stripe_product' | null
has_oriole_project: boolean
id: number
name: string
@@ -9818,6 +9881,7 @@ export interface components {
UpdateGoTrueConfigBody: {
API_MAX_REQUEST_DURATION?: number | null
AUDIT_LOG_DISABLE_POSTGRES?: boolean | null
+ CUSTOM_OAUTH_ENABLED?: boolean
DB_MAX_POOL_SIZE?: number | null
/** @enum {string|null} */
DB_MAX_POOL_SIZE_UNIT?: 'connections' | 'percent' | null
@@ -17173,7 +17237,9 @@ export interface operations {
| 'auth.user_sessions'
| 'auth.leaked_password_protection'
| 'auth.advanced_auth_settings'
+ | 'auth.performance_settings'
| 'backup.retention_days'
+ | 'backup.restore_to_new_project'
| 'function.max_count'
| 'function.size_limit_mb'
| 'realtime.max_concurrent_users'
@@ -17188,6 +17254,7 @@ export interface operations {
| 'project_pausing'
| 'project_cloning'
| 'assistant.advance_model'
+ | 'integrations.github_connections'
}
header?: never
path?: never
@@ -22735,8 +22802,6 @@ export interface operations {
query: {
cloud_provider: 'AWS' | 'FLY' | 'AWS_K8S' | 'AWS_NIMBUS'
desired_instance_size?:
- | 'pico'
- | 'nano'
| 'micro'
| 'small'
| 'medium'
@@ -26361,6 +26426,48 @@ export interface operations {
}
}
}
+ AccountRequestsController_getAccountRequest: {
+ parameters: {
+ query?: never
+ header?: never
+ path: {
+ id: string
+ }
+ cookie?: never
+ }
+ requestBody?: never
+ responses: {
+ 200: {
+ headers: {
+ [name: string]: unknown
+ }
+ content: {
+ 'application/json': components['schemas']['AccountRequestDetailsDto']
+ }
+ }
+ }
+ }
+ AccountRequestsController_confirmAccountRequest: {
+ parameters: {
+ query?: never
+ header?: never
+ path: {
+ id: string
+ }
+ cookie?: never
+ }
+ requestBody?: never
+ responses: {
+ 200: {
+ headers: {
+ [name: string]: unknown
+ }
+ content: {
+ 'application/json': components['schemas']['ConfirmResponseDto']
+ }
+ }
+ }
+ }
SetupIntentController_setUpPaymentMethod: {
parameters: {
query?: never
diff --git a/packages/common/first-referrer-cookie.ts b/packages/common/first-referrer-cookie.ts
index cfa7d6b7131..f45d4db782d 100644
--- a/packages/common/first-referrer-cookie.ts
+++ b/packages/common/first-referrer-cookie.ts
@@ -233,7 +233,10 @@ export function shouldRefreshCookie(
* (localhost, preview deploys) the domain is left unset so the browser
* stores a host-only cookie instead of rejecting an invalid domain.
*/
-export function stampFirstReferrerCookie(request: MiddlewareRequest, response: MiddlewareResponse): void {
+export function stampFirstReferrerCookie(
+ request: MiddlewareRequest,
+ response: MiddlewareResponse
+): void {
const referrer = request.headers.get('referer') ?? ''
const { stamp } = shouldRefreshCookie(request.cookies.has(FIRST_REFERRER_COOKIE_NAME), {
diff --git a/packages/ui-patterns/src/MobileSheetNav/index.ts b/packages/ui-patterns/src/MobileSheetNav/index.ts
index 06b0a825691..973dc94d731 100644
--- a/packages/ui-patterns/src/MobileSheetNav/index.ts
+++ b/packages/ui-patterns/src/MobileSheetNav/index.ts
@@ -1 +1 @@
-export { default as MobileSheetNav } from './MobileSheetNav'
\ No newline at end of file
+export { default as MobileSheetNav } from './MobileSheetNav'