Files
supabase/apps/studio/data/oauth-apps/oauth-apps-revoke-grant-mutation.ts
Gildas Garcia 4442d91d77 feat(studio): Wire org and users authorized apps list to backend (#53674)
## Description

Part of the work for OAuth apps with the scoped permissions. This PR
wires the org and users authorized apps lists to backend.
2026-11-19 21:40:12 +01:00

49 lines
1.5 KiB
TypeScript

import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { del, handleError } from '../fetchers'
import { oauthAppsKeys } from './keys'
import type { StudioError } from '@/lib/errors/studio-errors'
import type { UseCustomMutationOptions } from '@/types'
export type OAuthGrantRevokeVariables = {
grantId?: string
}
export async function revokeOAuthGrant({ grantId }: OAuthGrantRevokeVariables) {
if (!grantId) throw new Error('Grant id is required')
const { error } = await del('/platform/profile/oauth/grants/{grant_id}', {
params: { path: { grant_id: grantId } },
})
if (error) handleError(error)
}
export type OAuthGrantRevokeData = Awaited<ReturnType<typeof revokeOAuthGrant>>
export const useOAuthGrantRevokeMutation = ({
onError,
onSuccess,
...options
}: Omit<
UseCustomMutationOptions<OAuthGrantRevokeData, StudioError, OAuthGrantRevokeVariables>,
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
return useMutation<OAuthGrantRevokeData, StudioError, OAuthGrantRevokeVariables>({
mutationFn: (vars) => revokeOAuthGrant(vars),
async onSuccess(data, variables, context) {
await queryClient.invalidateQueries({ queryKey: oauthAppsKeys.grants() })
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to revoke OAuth grant: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
})
}