mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
Small improvements
This commit is contained in:
1 parent
ac10f883b6
commit
6c8952711d
2 files changed
+7
-23
No files matched your search
@@ -24,29 +24,12 @@ export async function getApiAuthorizationDetails(
|
||||
if (!id) throw new Error('Authorization ID is required')
|
||||
|
||||
const response = await get(`${API_ADMIN_URL}/oauth/authorizations/${id}`, { signal })
|
||||
if (response.error) {
|
||||
// 404 is a valid error in which the auth id is invalid
|
||||
const isInvalid =
|
||||
(response.error as any)?.code === 404 &&
|
||||
(response.error as any)?.message?.includes('OAuth authorization request does not exist')
|
||||
|
||||
if (isInvalid) {
|
||||
return {
|
||||
name: '',
|
||||
website: '',
|
||||
domain: '',
|
||||
expires_at: '',
|
||||
approved_at: null,
|
||||
} as ApiAuthorizationResponse
|
||||
}
|
||||
|
||||
throw response.error
|
||||
}
|
||||
if (response.error) throw response.error
|
||||
return response as ApiAuthorizationResponse
|
||||
}
|
||||
|
||||
export type ResourceData = Awaited<ReturnType<typeof getApiAuthorizationDetails>>
|
||||
export type ResourceError = unknown
|
||||
export type ResourceError = { errorEventId: string; message: string }
|
||||
|
||||
export const useApiAuthorizationQuery = <TData = ResourceData>(
|
||||
{ id }: ApiAuthorizationVariables,
|
||||
|
||||
@@ -24,9 +24,8 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
|
||||
const [selectedOrg, setSelectedOrg] = useState<string>()
|
||||
|
||||
const { data: organizations, isLoading: isLoadingOrganizations } = useOrganizationsQuery()
|
||||
const { data: requester, isLoading, isError } = useApiAuthorizationQuery({ id: auth_id })
|
||||
const { data: requester, isLoading, isError, error } = useApiAuthorizationQuery({ id: auth_id })
|
||||
const isApproved = requester?.approved_at !== null
|
||||
const isInvalid = requester?.name.length === 0 && requester.expires_at.length === 0
|
||||
const isExpired = dayjs().isAfter(dayjs(requester?.expires_at))
|
||||
|
||||
const { mutateAsync: approveRequest } = useApiAuthorizationApproveMutation()
|
||||
@@ -75,6 +74,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
|
||||
try {
|
||||
setIsSubmitting(true)
|
||||
await declineRequest({ id: auth_id })
|
||||
ui.setNotification({ category: 'success', message: 'Declined API authorization request' })
|
||||
router.push('/projects')
|
||||
} catch (error: any) {
|
||||
ui.setNotification({
|
||||
@@ -109,7 +109,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
|
||||
)
|
||||
}
|
||||
|
||||
if (isInvalid || isError) {
|
||||
if (isError) {
|
||||
return (
|
||||
<FormPanel header={<p>Authorize API access</p>}>
|
||||
<div className="w-[500px] px-8 py-6">
|
||||
@@ -118,7 +118,8 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
|
||||
variant="warning"
|
||||
title="Failed to fetch details for API authorization request"
|
||||
>
|
||||
Please retry your authorization request from the requesting app
|
||||
<p>Please retry your authorization request from the requesting app</p>
|
||||
{error !== undefined && <p className="mt-2">Error: {error?.message}</p>}
|
||||
</Alert>
|
||||
</div>
|
||||
</FormPanel>
|
||||
|
||||
Reference in new issue
Block a user