mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Description Part of the work for OAuth apps with the scoped permissions. This PR wires the org and users authorized apps lists to backend.
49 lines
1.5 KiB
TypeScript
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,
|
|
})
|
|
}
|