From 527057fc5ac15d074baf44edd2e65e05689990f1 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Tue, 24 Jun 2025 13:45:43 -0400 Subject: [PATCH] Get rid of the early access gating (#125) --- .../app/(centered)/select-org/SelectOrg.tsx | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/apps/web/src/app/(centered)/select-org/SelectOrg.tsx b/apps/web/src/app/(centered)/select-org/SelectOrg.tsx index c0e61bb000..9ff3682f28 100644 --- a/apps/web/src/app/(centered)/select-org/SelectOrg.tsx +++ b/apps/web/src/app/(centered)/select-org/SelectOrg.tsx @@ -1,14 +1,16 @@ 'use client'; -import Link from 'next/link'; -import { OrganizationList, useOrganizationList } from '@clerk/nextjs'; +import { useEffect } from 'react'; +import { useRouter } from 'next/navigation'; +import { OrganizationList, useOrganizationList, useClerk } from '@clerk/nextjs'; import { LoaderCircle } from 'lucide-react'; import { useAuthState } from '@/hooks/useAuthState'; -import { Button } from '@/components/ui'; export const SelectOrg = () => { const authState = useAuthState(); + const router = useRouter(); + const { setActive } = useClerk(); const { isLoaded, userMemberships, userSuggestions, userInvitations } = useOrganizationList({ @@ -27,30 +29,39 @@ export const SelectOrg = () => { userInvitations.isLoading || userSuggestions.isLoading; + // Auto-redirect if user has no organizations or exactly one organization + useEffect(() => { + if (isLoaded) { + const membershipCount = userMemberships.data?.length || 0; + + if (membershipCount === 0) { + // No organizations - redirect directly + router.push(redirectUrl); + } else if (membershipCount === 1) { + // One organization - set it as active and redirect + const singleOrg = userMemberships.data[0]; + if (singleOrg) { + setActive({ organization: singleOrg.organization.id }) + .then(() => { + router.push(redirectUrl); + }) + .catch((error: unknown) => { + console.error('Failed to set active organization:', error); + // If setting active org fails, fall back to showing the org list + }); + } + } + } + }, [isLoaded, userMemberships.data, redirectUrl, router, setActive]); + if (isLoading) { return ; } - const isBlocked = - userMemberships.count === 0 && - userInvitations.count === 0 && - userSuggestions.count === 0; - - if (isBlocked) { - return ( -
-
-
Roo Code Cloud is in closed beta.
-
- -
-
-
- ); + // If user has 0 or 1 organizations, show loading while redirecting + const membershipCount = userMemberships.data?.length || 0; + if (membershipCount === 0 || membershipCount === 1) { + return ; } return (