Skip to content

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

feat: Project claim (#35992)

Ivan Vasilov586a82982865
diff --git a/apps/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx b/apps/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
index d66d088734e..1e7b3555c4b 100644
--- a/apps/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
+++ b/apps/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
@@ -123,6 +123,7 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {
const [searchParams] = useQueryStates({
returnTo: parseAsString.withDefault(''),
auth_id: parseAsString.withDefault(''),
+ token: parseAsString.withDefault(''),
})
const updateForm = (key: keyof FormState, value: unknown) => {
@@ -161,9 +162,15 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {
: 'My Project'
if (searchParams.returnTo && searchParams.auth_id) {
- router.push(`${searchParams.returnTo}?auth_id=${searchParams.auth_id}`, undefined, {
- shallow: false,
- })
+ router.push(
+ `${searchParams.returnTo}?auth_id=${searchParams.auth_id}${
+ searchParams.token && `&token=${searchParams.token}&org=${org.name}`
+ }`,
+ undefined,
+ {
+ shallow: false,
+ }
+ )
} else {
router.push(`/new/${org.slug}?projectName=${prefilledProjectName}`)
}
diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails.tsx
index fe2a4ce16fb..94ada25c2d2 100644
--- a/apps/studio/components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails.tsx
+++ b/apps/studio/components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails.tsx
@@ -8,7 +8,7 @@ export interface AuthorizeRequesterDetailsProps {
scopes: OAuthScope[]
}
-const ScopeSection = ({
+export const ScopeSection = ({
description,
hasReadScope,
hasWriteScope,
diff --git a/apps/studio/components/interfaces/Organization/ProjectClaim/benefits.tsx b/apps/studio/components/interfaces/Organization/ProjectClaim/benefits.tsx
new file mode 100644
index 00000000000..383d85287b4
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/ProjectClaim/benefits.tsx
@@ -0,0 +1,91 @@
+import { CheckCircle2 } from 'lucide-react'
+
+import { ApiAuthorizationResponse } from 'data/api-authorization/api-authorization-query'
+import { OrganizationProjectClaimResponse } from 'data/organizations/organization-project-claim-query'
+import { Button } from 'ui'
+import { ProjectClaimLayout } from './layout'
+
+export const ProjectClaimBenefits = ({
+ projectClaim,
+ requester,
+ onContinue,
+}: {
+ projectClaim: OrganizationProjectClaimResponse
+ requester: ApiAuthorizationResponse
+ onContinue: () => void
+}) => {
+ return (
+ <ProjectClaimLayout
+ title={
+ <>
+ Claim a project <span className="text-brand">{projectClaim?.project?.name}</span> from{' '}
+ <span className="text-brand">{requester?.name}</span>
+ </>
+ }
+ >
+ <div className="space-y-8 text-sm flex flex-col items-center">
+ <div className="space-y-4 mt-6">
+ <h3 className="">Why manage your database project on Supabase?</h3>
+ <ul className="space-y-3">
+ <li className="flex space-x-2">
+ <CheckCircle2 className="text-brand w-5 h-5" />
+ <span>
+ <span className="text-foreground-light">Excellent Technical Support</span>
+ <span className="block text-foreground-lighter">
+ Get expert help when you need it, with support ready to assist your development
+ process.
+ </span>
+ </span>
+ </li>
+ <li className="flex space-x-2">
+ <CheckCircle2 className="text-brand w-5 h-5" />
+ <span>
+ <span className="text-foreground-light">Unrestricted usage.</span>
+ <span className="block text-foreground-lighter">
+ Grow your application without hitting arbitrary usage caps—built to scale with
+ you.
+ </span>
+ </span>
+ </li>
+ <li className="flex space-x-2">
+ <CheckCircle2 className="text-brand w-5 h-5" />
+ <span>
+ <span className="text-foreground-light">Visibility into your data.</span>
+ <span className="block text-foreground-lighter">
+ You'll have full control over your data to help your users get the best
+ experience.
+ </span>
+ </span>
+ </li>
+ <li className="flex space-x-2">
+ <CheckCircle2 className="text-brand w-5 h-5" />
+ <span>
+ <span className="text-foreground-light">Observability and easy debugging.</span>
+ <span className="block text-foreground-lighter">
+ You'll have full view when things go wrong.
+ </span>
+ </span>
+ </li>
+ <li className="flex space-x-2">
+ <div>
+ <CheckCircle2 className="text-brand w-5 h-5" />
+ </div>
+ <span>
+ <span className="text-foreground-light">Easy Compute Scaling.</span>
+ <span className="block text-foreground-lighter">
+ Upgrade compute resources to handle increased traffic and larger database
+ operations smoothly.
+ </span>
+ </span>
+ </li>
+ </ul>
+ </div>
+ <div className="flex justify-center sticky bottom-0">
+ <Button size="medium" onClick={onContinue}>
+ Continue connection
+ </Button>
+ </div>
+ </div>
+ </ProjectClaimLayout>
+ )
+}
diff --git a/apps/studio/components/interfaces/Organization/ProjectClaim/choose-org.tsx b/apps/studio/components/interfaces/Organization/ProjectClaim/choose-org.tsx
new file mode 100644
index 00000000000..fd8ff8217f5
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/ProjectClaim/choose-org.tsx
@@ -0,0 +1,24 @@
+import { OrganizationSelector } from 'components/ui/org-selector'
+import { Organization } from 'types'
+import { ProjectClaimLayout } from './layout'
+
+export interface ProjectClaimChooseOrgProps {
+ onChoose: (org: Organization) => void
+}
+
+const MAX_ORGS_TO_SHOW = 5
+
+export function ProjectClaimChooseOrg({ onChoose }: ProjectClaimChooseOrgProps) {
+ return (
+ <ProjectClaimLayout title="Claim a project">
+ <div className="mx-auto gap-y-4 py-6 flex flex-col">
+ <p className="text-sm text-foreground-light">
+ This is the first step in claiming your Supabase project. Once you're finished, the
+ project will be transferred to Supabase organization.
+ </p>
+ <p className="text-sm text-foreground-light">Please select an organization to continue.</p>
+ <OrganizationSelector onSelect={onChoose} maxOrgsToShow={MAX_ORGS_TO_SHOW} />
+ </div>
+ </ProjectClaimLayout>
+ )
+}
diff --git a/apps/studio/components/interfaces/Organization/ProjectClaim/confirm.tsx b/apps/studio/components/interfaces/Organization/ProjectClaim/confirm.tsx
new file mode 100644
index 00000000000..ae35c170dee
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/ProjectClaim/confirm.tsx
@@ -0,0 +1,255 @@
+import { OAuthScope } from '@supabase/shared-types/out/constants'
+import { CheckCircle2, ChevronRight, ChevronsLeftRight } from 'lucide-react'
+import Image from 'next/image'
+import { useRouter } from 'next/router'
+import { toast } from 'sonner'
+
+import { useQueryClient } from '@tanstack/react-query'
+import { useParams } from 'common'
+import { ApiAuthorizationResponse } from 'data/api-authorization/api-authorization-query'
+import { useOrganizationProjectClaimMutation } from 'data/organizations/organization-project-claim-mutation'
+import { OrganizationProjectClaimResponse } from 'data/organizations/organization-project-claim-query'
+import { projectKeys } from 'data/projects/keys'
+import { BASE_PATH } from 'lib/constants'
+import { Organization } from 'types'
+import {
+ Button,
+ cn,
+ Collapsible_Shadcn_,
+ CollapsibleContent_Shadcn_,
+ CollapsibleTrigger_Shadcn_,
+} from 'ui'
+import { Admonition } from 'ui-patterns/admonition'
+import { ScopeSection } from '../OAuthApps/AuthorizeRequesterDetails'
+import { ProjectClaimLayout } from './layout'
+
+export const ProjectClaimConfirm = ({
+ selectedOrganization,
+ projectClaim,
+ requester,
+ setStep,
+}: {
+ selectedOrganization: Organization
+ projectClaim: OrganizationProjectClaimResponse
+ requester: ApiAuthorizationResponse
+ setStep: (step: 'choose-org' | 'benefits' | 'confirm') => void
+}) => {
+ const router = useRouter()
+ const { token: claimToken } = useParams()
+ const queryClient = useQueryClient()
+
+ const { mutate: claimProject, isLoading } = useOrganizationProjectClaimMutation({
+ onSuccess: () => {
+ toast.success('Project claimed successfully')
+ // invalidate the org projects to force them to be refetched
+ queryClient.invalidateQueries(projectKeys.list())
+ router.push(`/org/${selectedOrganization.slug}`)
+ },
+ onError: (error) => {
+ toast.error(`Failed to claim project ${error.message}`)
+ },
+ })
+
+ return (
+ <ProjectClaimLayout
+ title={
+ <>
+ Claim a project <span className="text-brand">{projectClaim?.project?.name}</span> from{' '}
+ <span className="text-brand">{requester?.name}</span>
+ </>
+ }
+ >
+ <div className="py-6 space-y-8 text-sm">
+ <div className="flex flex-col items-center mt-6">
+ <div className="flex items-center">
+ <div
+ className={cn(
+ 'w-8 h-8 bg-center bg-no-repeat bg-cover flex items-center justify-center rounded-md'
+ )}
+ style={{
+ backgroundImage: !!requester.icon ? `url('${requester.icon}')` : 'none',
+ }}
+ >
+ {!requester.icon && (
+ <p className="text-foreground-light text-lg">{requester.name[0]}</p>
+ )}
+ </div>
+
+ <div className="flex items-center justify-center w-28 relative">
+ <div className="h-0.5 w-full border-2 border-dashed border-stronger" />
+ <div className="rounded-full border flex items-center justify-center h-10 w-full shadow-sm">
+ <ChevronsLeftRight className="text-muted-foreground" size={24} />
+ </div>
+ <div className="h-0.5 w-full border-2 border-dashed border-stronger z-10" />
+ </div>
+
+ <div className="w-8 h-8">
+ <Image
+ src={`${BASE_PATH}/img/supabase-logo.svg`}
+ alt="Supabase Logo"
+ className="w-full h-full"
+ width={100}
+ height={100}
+ />
+ </div>
+ </div>
+ </div>
+ <div className="space-y-4 text-foreground-light">
+ <p>
+ By claiming the <span className="text-foreground">{projectClaim?.project?.name}</span>{' '}
+ project from <span className="text-foreground">{requester?.name}</span>, the following
+ will happen:
+ </p>
+ <ul className="space-y-3">
+ <li className="flex space-x-2">
+ <span>
+ <CheckCircle2 className="text-brand h-5 w-5" />
+ </span>
+ <span>
+ The project will be transferred to your Supabase organization{' '}
+ <span className="text-foreground">{selectedOrganization.name}.</span>{' '}
+ <a
+ href="#"
+ onClick={() => setStep('choose-org')}
+ className="text-foreground-light underline"
+ >
+ Choose another organization?
+ </a>
+ </span>
+ </li>
+ <li className="flex space-x-2">
+ <span>
+ <CheckCircle2 className="text-brand h-5 w-5" />
+ </span>
+ <span>
+ <span className="text-foreground">{requester?.name}</span> will receive API access
+ (permissions listed below) to all projects within your organization to continue
+ providing its functionality to the application you've built.
+ </span>
+ </li>
+ <li className="flex space-x-2">
+ <span>
+ <CheckCircle2 className="text-brand h-5 w-5" />
+ </span>
+ <span>
+ You'll be responsible for maintaining the project, which may include additional
+ costs.
+ </span>
+ </li>
+ </ul>
+ <Admonition type="caution">
+ <div className="text-foreground-light">
+ Upon claiming, the project may undergo a short downtime (less than 10 minutes) for
+ resizing.
+ </div>
+ </Admonition>
+ </div>
+ <div className="flex space-y-4 flex-col">
+ {requester.scopes.length === 0 ? (
+ <span className="text-foreground-light">
+ <span className="text-foreground">{requester?.name}</span> hasn't requested any
+ permissions to operate. This is normal and no action is needed from your side.
+ </span>
+ ) : (
+ <Collapsible_Shadcn_>
+ <CollapsibleTrigger_Shadcn_ className="pb-3 w-full flex items-center justify-between group">
+ <p className="text-sm text-foreground-light text-left">
+ <span className="font-foreground">List of permissions</span> that{' '}
+ <span className="text-foreground">{requester.name}</span> will have for the{' '}
+ <span className="text-amber-900">
+ selected organization and all of its projects.
+ </span>
+ </p>
+
+ <ChevronRight
+ size={16}
+ className="text-foreground-light transition-all group-data-[state=open]:rotate-90 w-20"
+ strokeWidth={1}
+ />
+ </CollapsibleTrigger_Shadcn_>
+ <CollapsibleContent_Shadcn_
+ className={cn(
+ 'flex flex-col gap-8 transition-all',
+ 'data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down'
+ )}
+ >
+ <div>
+ <ScopeSection
+ description="access to analytics logs."
+ hasReadScope={requester.scopes.includes(OAuthScope.ANALYTICS_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.ANALYTICS_WRITE)}
+ />
+ <ScopeSection
+ description="access to auth configurations and SSO providers."
+ hasReadScope={requester.scopes.includes(OAuthScope.AUTH_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.AUTH_WRITE)}
+ />
+ <ScopeSection
+ description="access to Postgres configurations, SQL snippets, SSL enforcement configurations and Typescript schema types."
+ hasReadScope={requester.scopes.includes(OAuthScope.DATABASE_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.DATABASE_WRITE)}
+ />
+ <ScopeSection
+ description="access to custom domains and vanity subdomains."
+ hasReadScope={requester.scopes.includes(OAuthScope.DOMAINS_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.DOMAINS_WRITE)}
+ />
+ <ScopeSection
+ description="access to edge functions."
+ hasReadScope={requester.scopes.includes(OAuthScope.EDGE_FUNCTIONS_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.EDGE_FUNCTIONS_WRITE)}
+ />
+ <ScopeSection
+ description="access to environments/branches."
+ hasReadScope={requester.scopes.includes(OAuthScope.ENVIRONMENT_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.ENVIRONMENT_WRITE)}
+ />
+ <ScopeSection
+ description="access to the organization and all its members."
+ hasReadScope={requester.scopes.includes(OAuthScope.ORGANIZATIONS_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.ORGANIZATIONS_WRITE)}
+ />
+ <ScopeSection
+ description="access to metadata, its upgrade status, network restrictions and network bans."
+ hasReadScope={requester.scopes.includes(OAuthScope.PROJECTS_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.PROJECTS_WRITE)}
+ />
+ <ScopeSection
+ description="access to PostgREST configurations."
+ hasReadScope={requester.scopes.includes(OAuthScope.REST_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.REST_WRITE)}
+ />
+ <ScopeSection
+ description="access to API keys, secrets and pgsodium configurations."
+ hasReadScope={requester.scopes.includes(OAuthScope.SECRETS_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.SECRETS_WRITE)}
+ />
+ <ScopeSection
+ description="access to storage buckets and files."
+ hasReadScope={requester.scopes.includes(OAuthScope.STORAGE_READ)}
+ hasWriteScope={requester.scopes.includes(OAuthScope.STORAGE_WRITE)}
+ />
+ </div>
+ </CollapsibleContent_Shadcn_>
+ </Collapsible_Shadcn_>
+ )}
+ </div>
+ </div>
+ <div className="flex justify-center sticky bottom-0">
+ <Button
+ size="medium"
+ loading={isLoading}
+ disabled={isLoading}
+ onClick={() =>
+ claimProject({
+ slug: selectedOrganization.slug,
+ token: claimToken!,
+ })
+ }
+ >
+ Claim project {projectClaim?.project?.name}
+ </Button>
+ </div>
+ </ProjectClaimLayout>
+ )
+}
diff --git a/apps/studio/components/interfaces/Organization/ProjectClaim/layout.tsx b/apps/studio/components/interfaces/Organization/ProjectClaim/layout.tsx
new file mode 100644
index 00000000000..3f11332c55b
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/ProjectClaim/layout.tsx
@@ -0,0 +1,39 @@
+import Image from 'next/image'
+import { PropsWithChildren, ReactNode } from 'react'
+
+import { UserDropdown } from 'components/interfaces/UserDropdown'
+import { FeedbackDropdown } from 'components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown'
+import { BASE_PATH } from 'lib/constants'
+import { Separator } from 'ui'
+
+export const ProjectClaimLayout = ({
+ children,
+ title,
+}: PropsWithChildren<{
+ title: ReactNode
+}>) => {
+ return (
+ <>
+ <div className="flex flex-row justify-between flex-grow mx-auto w-full h-[52px] items-center px-4">
+ <div className="flex items-center gap-2">
+ <span className="sr-only">Supabase</span>
+ <Image
+ src={`${BASE_PATH}/img/supabase-logo.svg`}
+ alt="Supabase Logo"
+ height={20}
+ width={20}
+ />
+ <span className="truncate">{title}</span>
+ </div>
+ <div className="flex items-center gap-x-2">
+ <FeedbackDropdown className="hidden xs:flex" />
+ <UserDropdown />
+ </div>
+ </div>
+ <Separator />
+ <div className="overflow-y-auto max-h-[calc(100vh-70px)] flex justify-center">
+ <div className="w-full max-w-md">{children}</div>
+ </div>
+ </>
+ )
+}
diff --git a/apps/studio/components/layouts/APIAuthorizationLayout.tsx b/apps/studio/components/layouts/APIAuthorizationLayout.tsx
index 3d5492ef00b..10a57ab76b7 100644
--- a/apps/studio/components/layouts/APIAuthorizationLayout.tsx
+++ b/apps/studio/components/layouts/APIAuthorizationLayout.tsx
@@ -18,20 +18,18 @@ const APIAuthorizationLayout = ({ children }: PropsWithChildren<APIAuthorization
<div>
<div className="mx-auto px-4 sm:px-6">
<div className="max-w-xl flex justify-between items-center mx-auto py-4">
- <div className="flex justify-start lg:w-0 lg:flex-1">
- <div>
- <span className="sr-only">Supabase</span>
- <Image
- src={
- resolvedTheme?.includes('dark')
- ? `${BASE_PATH}/img/supabase-dark.svg`
- : `${BASE_PATH}/img/supabase-light.svg`
- }
- alt="Supabase Logo"
- height={20}
- width={105}
- />
- </div>
+ <div className="flex justify-start lg:w-0 lg:flex-1 items-center">
+ <span className="sr-only">Supabase</span>
+ <Image
+ src={
+ resolvedTheme?.includes('dark')
+ ? `${BASE_PATH}/img/supabase-dark.svg`
+ : `${BASE_PATH}/img/supabase-light.svg`
+ }
+ alt="Supabase Logo"
+ height={20}
+ width={105}
+ />
</div>
</div>
</div>
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
index 2fcbc4825da..5f02871ce14 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
@@ -5,7 +5,7 @@ import { useState } from 'react'
import { Button, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, Popover_Shadcn_ } from 'ui'
import { FeedbackWidget } from './FeedbackWidget'
-const FeedbackDropdown = () => {
+const FeedbackDropdown = ({ className }: { className?: string }) => {
const [isOpen, setIsOpen] = useState(false)
const [feedback, setFeedback] = useState('')
const [screenshot, setScreenshot] = useState<string>()
@@ -31,7 +31,7 @@ const FeedbackDropdown = () => {
type="outline"
className="rounded-full h-[32px] border-border"
>
- <span className="hidden md:flex">Feedback</span>
+ <span className={className}>Feedback</span>
</Button>
</PopoverTrigger_Shadcn_>
<PopoverContent_Shadcn_
diff --git a/apps/studio/components/ui/GlobalErrorBoundaryState.tsx b/apps/studio/components/ui/GlobalErrorBoundaryState.tsx
index fbe2f76a020..87bb6b27f22 100644
--- a/apps/studio/components/ui/GlobalErrorBoundaryState.tsx
+++ b/apps/studio/components/ui/GlobalErrorBoundaryState.tsx
@@ -58,7 +58,7 @@ export const GlobalErrorBoundaryState = ({ error, resetErrorBoundary }: Fallback
<div className="flex flex-col gap-y-4 max-w-full sm:max-w-[660px] px-4 sm:px-0">
<div className="flex flex-col gap-y-1 text-left py-2 w-full">
<div className="flex items-center justify-between mb-3">
- <p className="text-lg font-bold">Sorry! An unexpected error occured.</p>
+ <p className="text-lg font-bold">Sorry! An unexpected error occurred.</p>
<CopyButton type="outline" text={errorMessage} copyLabel="Copy error" />
</div>
<p className="text-sm">
diff --git a/apps/studio/components/ui/org-selector.tsx b/apps/studio/components/ui/org-selector.tsx
new file mode 100644
index 00000000000..94fc1c6ad07
--- /dev/null
+++ b/apps/studio/components/ui/org-selector.tsx
@@ -0,0 +1,121 @@
+import { ChevronDown } from 'lucide-react'
+import Link from 'next/link'
+import { useMemo, useState } from 'react'
+
+import ShimmeringLoader from 'components/ui/ShimmeringLoader'
+import { useOrganizationsQuery } from 'data/organizations/organizations-query'
+import { parseAsString, useQueryState } from 'nuqs'
+import { Organization } from 'types'
+import { Badge, Button, Card, CardHeader, CardTitle, Input_Shadcn_ } from 'ui'
+
+export interface ProjectClaimChooseOrgProps {
+ onSelect: (org: Organization) => void
+ maxOrgsToShow?: number
+}
+
+export function OrganizationSelector({ onSelect, maxOrgsToShow = 5 }: ProjectClaimChooseOrgProps) {
+ const {
+ data: organizations = [],
+ isLoading: isLoadingOrgs,
+ isSuccess: isSuccessOrgs,
+ isError: isErrorOrgs,
+ } = useOrganizationsQuery()
+
+ const [search, setSearch] = useQueryState(
+ 'org',
+ parseAsString.withDefault('').withOptions({ clearOnDefault: true })
+ )
+ const [showAll, setShowAll] = useState(false)
+
+ const filteredOrgs = useMemo(() => {
+ if (!search) {
+ return showAll ? organizations : organizations.slice(0, maxOrgsToShow)
+ }
+ return organizations.filter((org) => org.name.toLowerCase().includes(search.toLowerCase()))
+ }, [organizations, search, showAll, maxOrgsToShow])
+
+ const searchParams = new URLSearchParams(location.search)
+ let pathname = location.pathname
+ const basePath = process.env.NEXT_PUBLIC_BASE_PATH
+ if (basePath) {
+ pathname = pathname.replace(basePath, '')
+ }
+
+ searchParams.set('returnTo', pathname)
+
+ return (
+ <div className="w-full flex flex-col gap-y-4">
+ {isLoadingOrgs ? (
+ <ShimmeringLoader />
+ ) : isErrorOrgs ? (
+ <div>Error</div>
+ ) : isSuccessOrgs && organizations.length === 0 ? (
+ <span className="text-sm text-foreground-light">
+ It seems you don't have any organizations yet.
+ </span>
+ ) : (
+ <>
+ <Input_Shadcn_
+ type="text"
+ value={search}
+ onChange={(e) => setSearch(e.target.value)}
+ placeholder="Search..."
+ />
+ <div>
+ {filteredOrgs.length === 0 && (
+ <div className="text-center text-foreground-light py-6">No organizations found.</div>
+ )}
+ {filteredOrgs.map((org) => (
+ <Card
+ key={org.id}
+ className="hover:bg-surface-200 rounded-none first:rounded-t-lg last:rounded-b-lg -mb-px"
+ >
+ <CardHeader className="flex flex-row justify-between border-none space-y-0 space-x-2">
+ <CardTitle className="flex items-center gap-2 min-w-0 flex-1">
+ <span className="truncate min-w-0" title={org.name}>
+ {org.name}
+ </span>
+ <Badge className="shrink-0">{org.plan?.name}</Badge>
+ </CardTitle>
+ <Button
+ size="small"
+ onClick={() => {
+ onSelect(org)
+ setSearch('')
+ }}
+ className="shrink-0"
+ >
+ Choose
+ </Button>
+ </CardHeader>
+ </Card>
+ ))}
+ {organizations.length > maxOrgsToShow && !showAll && !search && (
+ <div className="flex justify-center py-2">
+ <Button
+ icon={<ChevronDown className="w-4 h-4" />}
+ size="tiny"
+ onClick={() => {
+ setSearch('')
+ setShowAll(true)
+ }}
+ type="default"
+ >
+ Show all organizations
+ </Button>
+ </div>
+ )}
+ </div>
+ </>
+ )}
+ <Card className="flex items-center justify-between border-dashed pr-6">
+ <CardHeader className="border-none">
+ <CardTitle>Need a new organization?</CardTitle>
+ </CardHeader>
+ <Button size="small" className="" asChild type="default">
+ <Link href={`/new?${searchParams.toString()}`}>New Organization</Link>
+ </Button>
+ </Card>
+ </div>
+ )
+}
diff --git a/apps/studio/data/organizations/keys.ts b/apps/studio/data/organizations/keys.ts
index 97b6940e4d6..dd33357640d 100644
--- a/apps/studio/data/organizations/keys.ts
+++ b/apps/studio/data/organizations/keys.ts
@@ -18,4 +18,6 @@ export const organizationKeys = {
taxId: (slug: string | undefined) => ['organizations', slug, 'tax-ids'] as const,
tokenValidation: (slug: string | undefined, token: string | undefined) =>
['organizations', slug, 'validate-token', token] as const,
+ projectClaim: (slug: string, token: string) =>
+ ['organizations', slug, 'project-claim', token] as const,
}
diff --git a/apps/studio/data/organizations/organization-project-claim-mutation.ts b/apps/studio/data/organizations/organization-project-claim-mutation.ts
new file mode 100644
index 00000000000..16d42a31571
--- /dev/null
+++ b/apps/studio/data/organizations/organization-project-claim-mutation.ts
@@ -0,0 +1,51 @@
+import { useMutation, UseMutationOptions } from '@tanstack/react-query'
+import { toast } from 'sonner'
+
+import { handleError, post } from 'data/fetchers'
+import type { ResponseError } from 'types'
+
+type OrganizationProjectClaimVariables = {
+ slug: string
+ token: string
+}
+
+async function claimOrganizationProject({ slug, token }: OrganizationProjectClaimVariables) {
+ const { data, error } = await post('/v1/organizations/{slug}/project-claim/{token}', {
+ params: { path: { slug, token } },
+ })
+ if (error) handleError(error)
+ return data
+}
+
+type ClaimOrganizationProjectData = Awaited<ReturnType<typeof claimOrganizationProject>>
+
+export const useOrganizationProjectClaimMutation = ({
+ onSuccess,
+ onError,
+ ...options
+}: Omit<
+ UseMutationOptions<
+ ClaimOrganizationProjectData,
+ ResponseError,
+ OrganizationProjectClaimVariables
+ >,
+ 'mutationFn'
+> = {}) => {
+ return useMutation<
+ ClaimOrganizationProjectData,
+ ResponseError,
+ OrganizationProjectClaimVariables
+ >((vars) => claimOrganizationProject(vars), {
+ async onSuccess(data, variables, context) {
+ await onSuccess?.(data, variables, context)
+ },
+ async onError(data, variables, context) {
+ if (onError === undefined) {
+ toast.error(`Failed to claim project: ${data.message}`)
+ } else {
+ onError(data, variables, context)
+ }
+ },
+ ...options,
+ })
+}
diff --git a/apps/studio/data/organizations/organization-project-claim-query.ts b/apps/studio/data/organizations/organization-project-claim-query.ts
new file mode 100644
index 00000000000..b02534661a2
--- /dev/null
+++ b/apps/studio/data/organizations/organization-project-claim-query.ts
@@ -0,0 +1,44 @@
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+import { organizationKeys } from './keys'
+
+import { components } from 'api-types'
+import { get, handleError } from 'data/fetchers'
+import type { ResponseError } from 'types'
+
+type OrganizationProjectClaimVariables = {
+ slug: string
+ token: string
+}
+
+export type OrganizationProjectClaimResponse =
+ components['schemas']['OrganizationProjectClaimResponse']
+
+async function getOrganizationProjectClaim(
+ { slug, token }: OrganizationProjectClaimVariables,
+ signal?: AbortSignal
+) {
+ if (!slug || !token) throw new Error('Slug and token are required')
+
+ const { data, error } = await get(`/v1/organizations/{slug}/project-claim/{token}`, {
+ params: { path: { slug, token } },
+ signal,
+ })
+
+ if (error) handleError(error)
+ return data
+}
+
+export type OrganizationProjectClaimData = Awaited<ReturnType<typeof getOrganizationProjectClaim>>
+export type OrganizationProjectClaimError = ResponseError
+
+export const useOrganizationProjectClaimQuery = <TData = OrganizationProjectClaimData>(
+ { slug, token }: OrganizationProjectClaimVariables,
+ {
+ ...options
+ }: UseQueryOptions<OrganizationProjectClaimData, OrganizationProjectClaimError, TData> = {}
+) =>
+ useQuery<OrganizationProjectClaimData, OrganizationProjectClaimError, TData>(
+ organizationKeys.projectClaim(slug, token),
+ ({ signal }) => getOrganizationProjectClaim({ slug, token }, signal),
+ { ...options }
+ )
diff --git a/apps/studio/pages/authorize.tsx b/apps/studio/pages/authorize.tsx
index 1cabb075613..49e60d48ac9 100644
--- a/apps/studio/pages/authorize.tsx
+++ b/apps/studio/pages/authorize.tsx
@@ -1,4 +1,3 @@
-import { useParams } from 'common'
import dayjs from 'dayjs'
import { AlertCircle } from 'lucide-react'
import Link from 'next/link'
@@ -6,6 +5,7 @@ import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { toast } from 'sonner'
+import { useParams } from 'common'
import AuthorizeRequesterDetails from 'components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails'
import APIAuthorizationLayout from 'components/layouts/APIAuthorizationLayout'
import { FormPanel } from 'components/ui/Forms/FormPanel'
diff --git a/apps/studio/pages/claim-project.tsx b/apps/studio/pages/claim-project.tsx
new file mode 100644
index 00000000000..a4851d99da7
--- /dev/null
+++ b/apps/studio/pages/claim-project.tsx
@@ -0,0 +1,127 @@
+import { useParams } from 'common'
+import { ProjectClaimBenefits } from 'components/interfaces/Organization/ProjectClaim/benefits'
+import { ProjectClaimChooseOrg } from 'components/interfaces/Organization/ProjectClaim/choose-org'
+import { ProjectClaimConfirm } from 'components/interfaces/Organization/ProjectClaim/confirm'
+import { ProjectClaimLayout } from 'components/interfaces/Organization/ProjectClaim/layout'
+import ShimmeringLoader from 'components/ui/ShimmeringLoader'
+import { useApiAuthorizationQuery } from 'data/api-authorization/api-authorization-query'
+import { useOrganizationProjectClaimQuery } from 'data/organizations/organization-project-claim-query'
+import { useOrganizationsQuery } from 'data/organizations/organizations-query'
+import { withAuth } from 'hooks/misc/withAuth'
+import Head from 'next/head'
+import { useMemo, useState } from 'react'
+import type { NextPageWithLayout } from 'types'
+import { Alert } from 'ui'
+
+const ClaimProjectPage: NextPageWithLayout = () => {
+ const { auth_id, token: claimToken } = useParams()
+ const [selectedOrgSlug, setSelectedOrgSlug] = useState<string>()
+ const [step, setStep] = useState<'choose-org' | 'benefits' | 'confirm'>('choose-org')
+
+ const {
+ data: requester,
+ isLoading: isLoadingRequester,
+ isError: isErrorRequester,
+ error: errorRequester,
+ } = useApiAuthorizationQuery({ id: auth_id })
+ const { data: organizations } = useOrganizationsQuery()
+
+ const selectedOrganization = useMemo(() => {
+ return (organizations || []).find((org) => org.slug === selectedOrgSlug)
+ }, [selectedOrgSlug, organizations])
+
+ const {
+ data: projectClaim,
+ error: errorProjectClaim,
+ isError: isErrorProjectClaim,
+ isLoading: isLoadingProjectClaim,
+ isSuccess: isSuccessProjectClaim,
+ } = useOrganizationProjectClaimQuery(
+ {
+ slug: selectedOrgSlug!,
+ token: claimToken!,
+ },
+ {
+ enabled: !!claimToken && !!selectedOrgSlug,
+ }
+ )
+
+ if ((selectedOrgSlug && claimToken && isLoadingProjectClaim) || isLoadingRequester) {
+ return (
+ <ProjectClaimLayout title="Claim a project">
+ <div className="py-6 space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ </ProjectClaimLayout>
+ )
+ }
+
+ if ((selectedOrgSlug && claimToken && isErrorProjectClaim) || isErrorRequester) {
+ return (
+ <ProjectClaimLayout title="Claim a project">
+ <div className="py-6">
+ <Alert
+ withIcon
+ variant="warning"
+ title="Failed to retrieve project claim request details"
+ >
+ <p>Please retry your claim request from the requesting app</p>
+ {errorProjectClaim != undefined && (
+ <p className="mt-2">Error: {errorProjectClaim?.message}</p>
+ )}
+ {errorRequester != undefined && (
+ <p className="mt-2">Error: {errorRequester?.message}</p>
+ )}
+ <p>Please go back to the requesting app and try again.</p>
+ </Alert>
+ </div>
+ </ProjectClaimLayout>
+ )
+ }
+
+ if (step === 'choose-org' || !selectedOrganization) {
+ return (
+ <ProjectClaimChooseOrg
+ onChoose={(org) => {
+ setSelectedOrgSlug(org.slug)
+ setStep('benefits')
+ }}
+ />
+ )
+ }
+
+ if (isSuccessProjectClaim) {
+ if (step === 'benefits') {
+ return (
+ <ProjectClaimBenefits
+ projectClaim={projectClaim}
+ requester={requester}
+ onContinue={() => setStep('confirm')}
+ />
+ )
+ }
+
+ return (
+ <ProjectClaimConfirm
+ setStep={setStep}
+ selectedOrganization={selectedOrganization}
+ projectClaim={projectClaim}
+ requester={requester}
+ />
+ )
+ }
+ return null
+}
+
+ClaimProjectPage.getLayout = (page) => (
+ <>
+ <Head>
+ <title>Claim project | Supabase</title>
+ </Head>
+ <main className="flex-grow flex flex-col w-full h-full overflow-y-auto">{page}</main>
+ </>
+)
+
+export default withAuth(ClaimProjectPage)