Skip to content

Commit c66c4d1

Browse files
authored
feat: Allow for preselecting organization when authorizing oauth app (supabase#37403)
1 parent e931323 commit c66c4d1

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

apps/studio/pages/authorize.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030

3131
const APIAuthorizationPage: NextPageWithLayout = () => {
3232
const router = useRouter()
33-
const { auth_id } = useParams()
33+
const { auth_id, organization_slug } = useParams()
3434
const [isApproving, setIsApproving] = useState(false)
3535
const [isDeclining, setIsDeclining] = useState(false)
3636
const [selectedOrgSlug, setSelectedOrgSlug] = useState<string>()
@@ -58,7 +58,11 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
5858

5959
useEffect(() => {
6060
if (isSuccessOrganizations && organizations.length > 0) {
61-
setSelectedOrgSlug(organizations[0].slug)
61+
if (organization_slug) {
62+
setSelectedOrgSlug(organizations.find(({ slug }) => slug === organization_slug)?.slug)
63+
} else {
64+
setSelectedOrgSlug(organizations[0].slug)
65+
}
6266
}
6367
// eslint-disable-next-line react-hooks/exhaustive-deps
6468
}, [isSuccessOrganizations])
@@ -168,7 +172,9 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
168172
<Button
169173
type="default"
170174
loading={isDeclining}
171-
disabled={isApproving || isExpired}
175+
disabled={
176+
isApproving || isExpired || (Boolean(organization_slug) && !selectedOrgSlug)
177+
}
172178
onClick={onDeclineRequest}
173179
>
174180
Decline
@@ -182,7 +188,9 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
182188
) : (
183189
<Button
184190
loading={isApproving}
185-
disabled={isDeclining || isExpired}
191+
disabled={
192+
isDeclining || isExpired || (Boolean(organization_slug) && !selectedOrgSlug)
193+
}
186194
onClick={onApproveRequest}
187195
>
188196
Authorize {requester?.name}
@@ -226,11 +234,27 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
226234
first.
227235
</AlertDescription_Shadcn_>
228236
</Alert_Shadcn_>
237+
) : organization_slug && !selectedOrgSlug ? (
238+
<Alert_Shadcn_ variant="warning">
239+
<AlertCircle className="h-4 w-4" />
240+
<AlertTitle_Shadcn_>
241+
Organization is needed for installing an integration
242+
</AlertTitle_Shadcn_>
243+
<AlertDescription_Shadcn_ className="">
244+
Your account is not a member of the pre-selected organization. To use this
245+
integration, it must be installed within an organization your account is associated
246+
with.
247+
</AlertDescription_Shadcn_>
248+
</Alert_Shadcn_>
229249
) : (
230250
<Listbox
231-
label="Select an organization to grant API access to"
251+
label={
252+
organization_slug
253+
? 'API access will be granted to pre-selected organization:'
254+
: 'Select an organization to grant API access to:'
255+
}
232256
value={selectedOrgSlug}
233-
disabled={isExpired}
257+
disabled={isExpired || Boolean(organization_slug)}
234258
onChange={setSelectedOrgSlug}
235259
>
236260
{(organizations ?? []).map((organization) => (

0 commit comments

Comments
 (0)