mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 07:09:07 +03:00
* fix: response error codes * upgrade docs * remove request url modification middleware * move api routes for self-hosted to platform folder * remove some lib/common/fetch usage * docs: use middleware for openapi-fetch (#30600) Get rid of the unauthedAllowedPost function (I don't think there's any harm in letting any requests that require authentication to just 403, they should be disabled at the React Query level and if not they will fail gracefully enough...) * fix local count query * add default values for clone mutation * fix ts and codegen * add missing lodash dep to playwright tests * Fix the playwright tests to match the new folder structure for selfhosted variant. * remove unused import * Remove unused state * remove unused sql debug mutation * remove unused export * fix notifications query * fix jwt updating status * fix typescript * save sql snippet after renaming * update codegen & fix ts error * override array querySerializer --------- Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { useMutation, UseMutationOptions } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { handleError, post } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import type { User } from './users-infinite-query'
|
|
|
|
export type UserResetPasswordVariables = {
|
|
projectRef: string
|
|
user: User
|
|
}
|
|
|
|
export async function resetPassword({ projectRef, user }: UserResetPasswordVariables) {
|
|
const { data, error } = await post('/platform/auth/{ref}/recover', {
|
|
params: { path: { ref: projectRef } },
|
|
body: user,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
|
|
return data
|
|
}
|
|
|
|
type UserResetPasswordData = Awaited<ReturnType<typeof resetPassword>>
|
|
|
|
export const useUserResetPasswordMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<UserResetPasswordData, ResponseError, UserResetPasswordVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
return useMutation<UserResetPasswordData, ResponseError, UserResetPasswordVariables>(
|
|
(vars) => resetPassword(vars),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
// [Joshen] If we need to invalidate any queries
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to reset user password: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|