mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
* Add custom types for queries, mutations and infinite queries. * Migrate all queries to use the new type. * Migrate all infinite queries to useCustomInfiniteQueryOptions. * Migrate all mutations to use useCustomMutationOptions. * Add type to all imports in `types` folder.
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import type { UserIdentity } from '@supabase/supabase-js'
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { auth } from 'lib/gotrue'
|
|
import { UseCustomMutationOptions } from 'types'
|
|
import { profileKeys } from './keys'
|
|
|
|
const unlinkIdentity = async (identity: UserIdentity) => {
|
|
const { error, data } = await auth.unlinkIdentity(identity)
|
|
|
|
if (error) throw error
|
|
return data
|
|
}
|
|
|
|
type UnlinkIdentityResponse = any
|
|
type UnlinkIdentityError = any
|
|
|
|
export const useUnlinkIdentityMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<UnlinkIdentityResponse, UnlinkIdentityError, UserIdentity>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: (vars) => unlinkIdentity(vars),
|
|
async onSuccess(data, variables, context) {
|
|
await Promise.all([
|
|
auth.refreshSession(),
|
|
queryClient.invalidateQueries({ queryKey: profileKeys.identities() }),
|
|
])
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to unlink identity: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|