Skip to content

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

fix(studio): align /authorize invalid and edge states with interstitial UI (#46960)

Danny White43c2229f1e11
diff --git a/apps/studio/components/interfaces/ApiAuthorization/ApiAuthorization.Invalid.tsx b/apps/studio/components/interfaces/ApiAuthorization/ApiAuthorization.Invalid.tsx
index 1ccfd92cea6..52e28b67ff5 100644
--- a/apps/studio/components/interfaces/ApiAuthorization/ApiAuthorization.Invalid.tsx
+++ b/apps/studio/components/interfaces/ApiAuthorization/ApiAuthorization.Invalid.tsx
@@ -1,5 +1,9 @@
+import Link from 'next/link'
import type { ReactNode } from 'react'
-import { Card, CardContent, CardHeader } from 'ui'
+import { Button } from 'ui'
+import { Admonition } from 'ui-patterns'
+
+import { InterstitialLayout, SupabaseLogo } from '@/components/layouts/InterstitialLayout'
export interface ApiAuthorizationInvalidScreenProps {
missingParameters: Array<string>
@@ -9,20 +13,24 @@ export function ApiAuthorizationInvalidScreen({
missingParameters,
}: ApiAuthorizationInvalidScreenProps): ReactNode {
const isPlural = missingParameters.length > 1
- const paragraphFontClass = 'text-sm text-muted-foreground'
return (
- <Card>
- <CardHeader>Missing parameters</CardHeader>
- <CardContent className="flex flex-col gap-2">
- <p className={paragraphFontClass}>
- Cannot authorize this request because the URL is missing the following parameter
- {isPlural ? 's' : ''}: {missingParameters.join(', ')}.
- </p>
- <p className={paragraphFontClass}>
- If you followed a link here, please check the link and try again.
- </p>
- </CardContent>
- </Card>
+ <InterstitialLayout
+ logo={<SupabaseLogo />}
+ title="Missing authorization link"
+ description="This authorization request cannot be completed"
+ >
+ <div className="flex flex-col gap-3 px-6 pb-6">
+ <Admonition
+ type="warning"
+ description={`Retry the authorization request from the requesting app. The URL is missing parameter${
+ isPlural ? 's' : ''
+ }: ${missingParameters.join(', ')}.`}
+ />
+ <Button type="default" block asChild>
+ <Link href="/">Back to dashboard</Link>
+ </Button>
+ </div>
+ </InterstitialLayout>
)
}
diff --git a/apps/studio/components/interfaces/ApiAuthorization/ApiAuthorization.Valid.tsx b/apps/studio/components/interfaces/ApiAuthorization/ApiAuthorization.Valid.tsx
index cb85776418a..507b06fa481 100644
--- a/apps/studio/components/interfaces/ApiAuthorization/ApiAuthorization.Valid.tsx
+++ b/apps/studio/components/interfaces/ApiAuthorization/ApiAuthorization.Valid.tsx
@@ -193,7 +193,9 @@ export function ApiAuthorizationValidScreen({
? buildStudioPageTitle({ section: `Authorize ${effectiveRequester.name}`, brand: 'Supabase' })
: undefined
- if (!effectiveRequester) return null
+ if (!effectiveRequester) {
+ return <ApiAuthorizationErrorScreen error={undefined} />
+ }
if (isApproved) {
const approvedOrganization =
diff --git a/apps/studio/pages/authorize.tsx b/apps/studio/pages/authorize.tsx
index 4dc816778d9..45921d5c34a 100644
--- a/apps/studio/pages/authorize.tsx
+++ b/apps/studio/pages/authorize.tsx
@@ -3,6 +3,7 @@ import Head from 'next/head'
import { useRouter } from 'next/router'
import { ApiAuthorizationScreen } from '@/components/interfaces/ApiAuthorization/ApiAuthorization'
+import { ApiAuthorizationLoadingScreen } from '@/components/interfaces/ApiAuthorization/ApiAuthorization.Loading'
import { withAuth } from '@/hooks/misc/withAuth'
import { buildStudioPageTitle } from '@/lib/page-title'
import type { NextPageWithLayout } from '@/types'
@@ -15,7 +16,14 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
const { auth_id, organization_slug } = useParams()
if (!routerReady) {
- return null
+ return (
+ <>
+ <Head>
+ <title>{PAGE_TITLE}</title>
+ </Head>
+ <ApiAuthorizationLoadingScreen />
+ </>
+ )
}
return (
diff --git a/apps/studio/tests/components/ApiAuthorization.test.tsx b/apps/studio/tests/components/ApiAuthorization.test.tsx
index 2ac4757a4f9..3affecce453 100644
--- a/apps/studio/tests/components/ApiAuthorization.test.tsx
+++ b/apps/studio/tests/components/ApiAuthorization.test.tsx
@@ -122,10 +122,12 @@ function renderScreen(props: Partial<ApiAuthorizationScreenProps> = {}) {
describe('ApiAuthorizationScreen', () => {
describe('when auth_id is missing', () => {
- test('renders invalid screen when auth_id is undefined', () => {
+ test('renders invalid interstitial when auth_id is undefined', () => {
renderScreen({ auth_id: undefined })
- expect(screen.getByText('Missing parameters')).toBeInTheDocument()
+ expect(screen.getByText('Missing authorization link')).toBeInTheDocument()
expect(screen.getByText(/auth_id/)).toBeInTheDocument()
+ expect(screen.getByAltText('Supabase')).toBeInTheDocument()
+ expect(screen.getByRole('link', { name: 'Back to dashboard' })).toHaveAttribute('href', '/')
})
})
@@ -153,6 +155,20 @@ describe('ApiAuthorizationScreen', () => {
await screen.findByText('Unable to load authorization')
})
+ test('renders error screen when authorization query returns no requester', async () => {
+ mockOrgsEndpoint()
+ addAPIMock({
+ method: 'get',
+ path: '/platform/oauth/authorizations/:id',
+ response: () =>
+ HttpResponse.json<GetOAuthAuthorizationResponse>(
+ null as unknown as GetOAuthAuthorizationResponse
+ ),
+ })
+ renderScreen()
+ await screen.findByText('Unable to load authorization')
+ })
+
describe('when already approved', () => {
test('renders approved screen with matching organization name', async () => {
mockBothEndpoints(
diff --git a/apps/studio/tests/pages/authorize.test.tsx b/apps/studio/tests/pages/authorize.test.tsx
new file mode 100644
index 00000000000..7561cce3406
--- /dev/null
+++ b/apps/studio/tests/pages/authorize.test.tsx
@@ -0,0 +1,50 @@
+import { screen } from '@testing-library/react'
+import { describe, expect, test, vi } from 'vitest'
+
+import type { ProfileContextType } from '@/lib/profile'
+import APIAuthorizationPage from '@/pages/authorize'
+import { customRender } from '@/tests/lib/custom-render'
+
+vi.mock('@/hooks/misc/withAuth', () => ({
+ withAuth: (Component: React.ComponentType) => Component,
+}))
+
+const routerPushMock = vi.fn()
+
+vi.mock('next/router', () => ({
+ useRouter: () => ({
+ isReady: false,
+ push: routerPushMock,
+ query: {},
+ }),
+}))
+
+const DEFAULT_PROFILE_CONTEXT: ProfileContextType = {
+ profile: {
+ id: 1,
+ auth0_id: 'auth0|test',
+ gotrue_id: 'gotrue-test',
+ username: 'testuser',
+ primary_email: '[email protected]',
+ first_name: null,
+ last_name: null,
+ mobile: null,
+ is_alpha_user: false,
+ is_sso_user: false,
+ disabled_features: [],
+ free_project_limit: null,
+ },
+ error: null,
+ isLoading: false,
+ isError: false,
+ isSuccess: true,
+}
+
+describe('APIAuthorizationPage', () => {
+ test('renders loading interstitial while router is not ready', () => {
+ customRender(<APIAuthorizationPage dehydratedState={{}} />, {
+ profileContext: DEFAULT_PROFILE_CONTEXT,
+ })
+ expect(screen.getByText('Loading...')).toBeInTheDocument()
+ })
+})