Skip to content

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

Add preview consent screen button

Joshen Lim469a1f4360da
diff --git a/studio/components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails.tsx b/studio/components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails.tsx
new file mode 100644
index 00000000000..96c760ace05
--- /dev/null
+++ b/studio/components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails.tsx
@@ -0,0 +1,33 @@
+export interface AuthorizeRequesterDetailsProps {
+ icon: string | null
+ name: string
+ domain: string
+}
+
+const AuthorizeRequesterDetails = ({ icon, name, domain }: AuthorizeRequesterDetailsProps) => {
+ return (
+ <div className="flex space-x-4">
+ <div>
+ <div className="rounded-md border border-scale-600 flex items-center">
+ <div
+ className="w-14 h-14 md:w-16 md:h-16 bg-center bg-no-repeat bg-cover flex items-center justify-center"
+ style={{
+ backgroundImage: icon !== null ? `url('${icon}')` : 'none',
+ }}
+ >
+ {icon === null && <p className="text-scale-1000 text-lg">{name[0]}</p>}
+ </div>
+ </div>
+ </div>
+ <p className="text-sm text-scale-1100">
+ {name} ({domain}) is requesting API access to an organization. The application will be able
+ to{' '}
+ <span className="text-amber-1200">
+ read and write the organization's settings and all of its projects.
+ </span>
+ </p>
+ </div>
+ )
+}
+
+export default AuthorizeRequesterDetails
diff --git a/studio/components/interfaces/Organization/OAuthApps/PublishAppModal.tsx b/studio/components/interfaces/Organization/OAuthApps/PublishAppModal.tsx
index 5b99f2a1af7..7b035b411f0 100644
--- a/studio/components/interfaces/Organization/OAuthApps/PublishAppModal.tsx
+++ b/studio/components/interfaces/Organization/OAuthApps/PublishAppModal.tsx
@@ -10,8 +10,9 @@ import { useOAuthAppUpdateMutation } from 'data/oauth/oauth-app-update-mutation'
import { OAuthApp } from 'data/oauth/oauth-apps-query'
import { useStore } from 'hooks'
import { isValidHttpUrl, uuidv4 } from 'lib/helpers'
-import { Button, Dropdown, Form, IconEdit, IconUpload, Input, Modal } from 'ui'
+import { Badge, Button, Dropdown, Form, IconEdit, IconUpload, Input, Modal } from 'ui'
import { uploadAttachment } from './OAuthApps.utils'
+import AuthorizeRequesterDetails from './AuthorizeRequesterDetails'
export interface PublishAppModalProps {
visible: boolean
@@ -32,6 +33,7 @@ const PublishAppModal = ({
const { mutateAsync: createOAuthApp } = useOAuthAppCreateMutation()
const { mutateAsync: updateOAuthApp } = useOAuthAppUpdateMutation()
+ const [showPreview, setShowPreview] = useState(false)
const [iconFile, setIconFile] = useState<File>()
const [iconUrl, setIconUrl] = useState<string>()
const [errors, setErrors] = useState<{ [key: string]: string }>({})
@@ -152,162 +154,236 @@ const PublishAppModal = ({
}
return (
- <Modal
- hideFooter
- visible={visible}
- header={
- selectedApp !== undefined ? 'Update OAutha application' : 'Publish a new OAuth application'
- }
- onCancel={() => onClose()}
- >
- <Form
- validateOnBlur
- initialValues={{ name: '', website: '' }}
- validate={validate}
- onSubmit={onSubmit}
+ <>
+ <Modal
+ hideFooter
+ visible={visible}
+ header={
+ selectedApp !== undefined
+ ? 'Update OAutha application'
+ : 'Publish a new OAuth application'
+ }
+ onCancel={() => onClose()}
>
- {({ isSubmitting, resetForm }: { isSubmitting: boolean; resetForm: any }) => {
- // [Joshen] although this "technically" is breaking the rules of React hooks
- // it won't error because the hooks are always rendered in the same order
- // eslint-disable-next-line react-hooks/rules-of-hooks
- useEffect(() => {
- if (visible && selectedApp !== undefined) {
- const values = { name: selectedApp.name, website: selectedApp.website }
- resetForm({ values, initialValues: values })
- }
- }, [visible, selectedApp])
+ <Form
+ validateOnBlur
+ initialValues={{ name: '', website: '' }}
+ validate={validate}
+ onSubmit={onSubmit}
+ >
+ {({
+ isSubmitting,
+ resetForm,
+ values,
+ }: {
+ isSubmitting: boolean
+ resetForm: any
+ values: any
+ }) => {
+ // [Joshen] although this "technically" is breaking the rules of React hooks
+ // it won't error because the hooks are always rendered in the same order
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ useEffect(() => {
+ if (visible && selectedApp !== undefined) {
+ const values = { name: selectedApp.name, website: selectedApp.website }
+ resetForm({ values, initialValues: values })
+ }
+ }, [visible, selectedApp])
- return (
- <div>
- <Modal.Content>
- <div className="py-4 flex items-start justify-between gap-10">
- <div className="space-y-4 w-full">
- <Input
- id="name"
- label="Application name"
- descriptionText={selectedApp?.id && `ID: ${selectedApp.id}`}
- ></Input>
- <Input
- id="website"
- label="Website URL"
- placeholder="https://my-website.com"
- ></Input>
- </div>
- <div>
- {iconUrl !== undefined ? (
- <div
- className={clsx(
- 'shadow transition group relative',
- 'bg-center bg-cover bg-no-repeat',
- 'mt-4 mr-4 space-y-2 rounded-full h-[120px] w-[120px] flex flex-col items-center justify-center'
- )}
- style={{
- backgroundImage: iconUrl ? `url("${iconUrl}")` : 'none',
- }}
- >
- <div className="absolute bottom-1 right-1">
- <Dropdown
- size="tiny"
- align="end"
- side="bottom"
- overlay={[
- <Dropdown.Item
- key="upload"
- onClick={() => {
- if (uploadButtonRef.current)
- (uploadButtonRef.current as any).click()
- }}
- >
- Upload image
- </Dropdown.Item>,
- <Dropdown.Item
- key="remove"
- onClick={() => {
- setIconFile(undefined)
- setIconUrl(undefined)
- }}
+ return (
+ <>
+ <div>
+ <Modal.Content>
+ <div className="py-4 flex items-start justify-between gap-10">
+ <div className="space-y-4 w-full">
+ <Input
+ id="name"
+ label="Application name"
+ descriptionText={selectedApp?.id && `ID: ${selectedApp.id}`}
+ />
+ <Input
+ id="website"
+ label="Website URL"
+ placeholder="https://my-website.com"
+ />
+ </div>
+ <div>
+ {iconUrl !== undefined ? (
+ <div
+ className={clsx(
+ 'shadow transition group relative',
+ 'bg-center bg-cover bg-no-repeat',
+ 'mt-4 mr-4 space-y-2 rounded-full h-[120px] w-[120px] flex flex-col items-center justify-center'
+ )}
+ style={{
+ backgroundImage: iconUrl ? `url("${iconUrl}")` : 'none',
+ }}
+ >
+ <div className="absolute bottom-1 right-1">
+ <Dropdown
+ size="tiny"
+ align="end"
+ side="bottom"
+ overlay={[
+ <Dropdown.Item
+ key="upload"
+ onClick={() => {
+ if (uploadButtonRef.current)
+ (uploadButtonRef.current as any).click()
+ }}
+ >
+ Upload image
+ </Dropdown.Item>,
+ <Dropdown.Item
+ key="remove"
+ onClick={() => {
+ setIconFile(undefined)
+ setIconUrl(undefined)
+ }}
+ >
+ Remove image
+ </Dropdown.Item>,
+ ]}
>
- Remove image
- </Dropdown.Item>,
- ]}
+ <Button type="default" icon={<IconEdit />} className="px-1" />
+ </Dropdown>
+ </div>
+ </div>
+ ) : (
+ <div
+ className={clsx(
+ 'border border-scale-700 transition opacity-75 hover:opacity-100',
+ 'mt-4 mr-4 space-y-2 rounded-full h-[120px] w-[120px] flex flex-col items-center justify-center cursor-pointer'
+ )}
+ onClick={() => {
+ if (uploadButtonRef.current) (uploadButtonRef.current as any).click()
+ }}
>
- <Button type="default" icon={<IconEdit />} className="px-1" />
- </Dropdown>
- </div>
- </div>
- ) : (
- <div
- className={clsx(
- 'border border-scale-700 transition opacity-75 hover:opacity-100',
- 'mt-4 mr-4 space-y-2 rounded-full h-[120px] w-[120px] flex flex-col items-center justify-center cursor-pointer'
+ <IconUpload size={18} strokeWidth={1.5} className="text-scale-1200" />
+ <p className="text-xs text-scale-1100">Upload logo</p>
+ </div>
)}
- onClick={() => {
- if (uploadButtonRef.current) (uploadButtonRef.current as any).click()
- }}
+ <input
+ multiple
+ type="file"
+ ref={uploadButtonRef}
+ className="hidden"
+ accept="image/png, image/jpeg"
+ onChange={onFileUpload}
+ />
+ </div>
+ </div>
+ </Modal.Content>
+
+ <Modal.Separator />
+
+ <Modal.Content>
+ <div className="mb-2 flex items-center justify-between">
+ <div>
+ <p className="prose text-sm">Allowed URLs</p>
+ <p className="text-sm text-scale-1000">
+ All URLs must use HTTPS, except for localhost
+ </p>
+ </div>
+ <Button onClick={() => setUrls(urls.concat({ id: uuidv4(), value: '' }))}>
+ Add URL
+ </Button>
+ </div>
+ <div className="space-y-2 pb-2">
+ {urls.map((url) => (
+ <Input
+ key={url.id}
+ value={url.value}
+ onChange={(event) => onUpdateUrl(url.id, event.target.value)}
+ placeholder="e.g https://my-website.com"
+ actions={[
+ urls.length > 1 ? (
+ <Button
+ key="remove-url"
+ type="default"
+ onClick={() => removeUrl(url.id)}
+ >
+ Remove
+ </Button>
+ ) : null,
+ ]}
+ />
+ ))}
+ {errors.urls && <p className="text-red-900 text-sm">{errors.urls}</p>}
+ </div>
+ </Modal.Content>
+
+ <Modal.Separator />
+
+ <Modal.Content>
+ <div className="pt-2 pb-3 flex items-center justify-between">
+ <Button
+ type="default"
+ onClick={() => setShowPreview(true)}
+ disabled={values.name.length === 0 || values.website.length === 0}
>
- <IconUpload size={18} strokeWidth={1.5} className="text-scale-1200" />
- <p className="text-xs text-scale-1100">Upload logo</p>
+ Preview consent for users
+ </Button>
+ <div className="flex items-center space-x-2">
+ <Button type="default" disabled={isSubmitting} onClick={() => onClose()}>
+ Cancel
+ </Button>
+ <Button htmlType="submit" loading={isSubmitting} disabled={isSubmitting}>
+ Confirm
+ </Button>
</div>
- )}
- <input
- multiple
- type="file"
- ref={uploadButtonRef}
- className="hidden"
- accept="image/png, image/jpeg"
- onChange={onFileUpload}
- />
- </div>
- </div>
- </Modal.Content>
- <Modal.Separator />
- <Modal.Content>
- <div className="mb-2 flex items-center justify-between">
- <div>
- <p className="prose text-sm">Allowed URLs</p>
- <p className="text-sm text-scale-1000">
- All URLs must use HTTPS, except for localhost
- </p>
- </div>
- <Button onClick={() => setUrls(urls.concat({ id: uuidv4(), value: '' }))}>
- Add URL
- </Button>
+ </div>
+ </Modal.Content>
</div>
- <div className="space-y-2 pb-2">
- {urls.map((url) => (
- <Input
- key={url.id}
- value={url.value}
- onChange={(event) => onUpdateUrl(url.id, event.target.value)}
- placeholder="e.g https://my-website.com"
- actions={[
- urls.length > 1 ? (
- <Button key="remove-url" type="default" onClick={() => removeUrl(url.id)}>
- Remove
- </Button>
- ) : null,
- ]}
- />
- ))}
- {errors.urls && <p className="text-red-900 text-sm">{errors.urls}</p>}
- </div>
- </Modal.Content>
- <Modal.Separator />
- <Modal.Content>
- <div className="pt-2 pb-3 flex items-center space-x-2 justify-end">
- <Button type="default" disabled={isSubmitting} onClick={() => onClose()}>
- Cancel
- </Button>
- <Button htmlType="submit" loading={isSubmitting} disabled={isSubmitting}>
- Confirm
- </Button>
- </div>
- </Modal.Content>
- </div>
- )
- }}
- </Form>
- </Modal>
+
+ <Modal
+ hideFooter
+ className="!w-[500px]"
+ visible={showPreview}
+ onCancel={() => setShowPreview(false)}
+ >
+ <Modal.Content>
+ <div className="pt-4 pb-2 px-2 flex items-center justify-between">
+ <p>Authorize API access for {values.name}</p>
+ <Badge color="green">Preview</Badge>
+ </div>
+ </Modal.Content>
+ <Modal.Separator />
+ <Modal.Content>
+ <div className="px-2 py-4">
+ <AuthorizeRequesterDetails
+ icon={iconUrl || null}
+ name={values.name}
+ domain={values.website}
+ />
+ <div className="pt-4 space-y-2">
+ <p className="prose text-sm">
+ Select an organization to grant API access to
+ </p>
+ <div className="border border-scale-600 text-scale-1000 rounded px-4 py-2 text-sm bg-scale-400">
+ Organizations that you have access to will be listed here
+ </div>
+ </div>
+ </div>
+ </Modal.Content>
+ <Modal.Separator />
+ <Modal.Content>
+ <div className="pt-2 pb-3 flex items-center justify-between">
+ <p className="prose text-xs">
+ This is what your users will see when authorizing with your app
+ </p>
+ <Button type="default" onClick={() => setShowPreview(false)}>
+ Close
+ </Button>
+ </div>
+ </Modal.Content>
+ </Modal>
+ </>
+ )
+ }}
+ </Form>
+ </Modal>
+ </>
)
}
diff --git a/studio/pages/authorize.tsx b/studio/pages/authorize.tsx
index a7f1c81e920..4d28fb24a67 100644
--- a/studio/pages/authorize.tsx
+++ b/studio/pages/authorize.tsx
@@ -1,4 +1,9 @@
+import dayjs from 'dayjs'
+import { useRouter } from 'next/router'
+import { useEffect, useState } from 'react'
+
import { useParams } from 'common'
+import AuthorizeRequesterDetails from 'components/interfaces/Organization/OAuthApps/AuthorizeRequesterDetails'
import APIAuthorizationLayout from 'components/layouts/APIAuthorizationLayout'
import { FormPanel } from 'components/ui/Forms'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
@@ -6,10 +11,7 @@ import { useApiAuthorizationApproveMutation } from 'data/api-authorization/api-a
import { useApiAuthorizationDeclineMutation } from 'data/api-authorization/api-authorization-decline-mutation'
import { useApiAuthorizationQuery } from 'data/api-authorization/api-authorization-query'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
-import dayjs from 'dayjs'
import { useStore, withAuth } from 'hooks'
-import { useRouter } from 'next/router'
-import { useEffect, useState } from 'react'
import { NextPageWithLayout } from 'types'
import { Alert, Button, Listbox } from 'ui'
@@ -170,30 +172,11 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
>
<div className="w-full md:w-[500px] px-8 py-6 space-y-8">
{/* API Authorization requester details */}
-
- <div className="flex space-x-4">
- <div>
- <div className="rounded-md border border-scale-600 p-2.5 flex items-center">
- <div
- className="w-8 h-8 md:w-10 md:h-10 bg-center bg-no-repeat bg-cover flex items-center justify-center"
- style={{
- backgroundImage: requester.icon !== null ? `url('${requester?.icon}')` : 'none',
- }}
- >
- {requester?.icon === null && (
- <p className="text-scale-1000 text-lg">{requester?.name[0]}</p>
- )}
- </div>
- </div>
- </div>
- <p className="text-sm text-scale-1100">
- {requester?.name} ({requester?.domain}) is requesting API access to an organization. The
- application will be able to{' '}
- <span className="text-amber-1200">
- read and write the organization's settings and all of its projects.
- </span>
- </p>
- </div>
+ <AuthorizeRequesterDetails
+ icon={requester.icon}
+ name={requester.name}
+ domain={requester.domain}
+ />
{/* Expiry warning */}
{isExpired && (