mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 06:09:08 +03:00
* Support updating email address for email identity * Support unlinking identity * Deprecate AccountInformation component * Invalidate identities after unlinking * Address feedback * Smol * Fix type issues * Update toast message * Set up email change pending badge * Fix * Address feedback * Resolve ts-expect-errors * Fix TS issues + Fix GH icon on light mode + Address feedback
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import type { UserIdentity } from '@supabase/supabase-js'
|
|
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { auth } from 'lib/gotrue'
|
|
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<
|
|
UseMutationOptions<UnlinkIdentityResponse, UnlinkIdentityError, UserIdentity>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
return useMutation((vars) => unlinkIdentity(vars), {
|
|
async onSuccess(data, variables, context) {
|
|
await Promise.all([
|
|
auth.refreshSession(),
|
|
queryClient.invalidateQueries(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,
|
|
})
|
|
}
|