**What** - add password reset flow on Admin --- https://github.com/user-attachments/assets/3438ace2-c661-4121-a580-794a69ad4518 --- CLOSES CC-568 Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { UseMutationOptions, useMutation } from "@tanstack/react-query"
|
|
import { FetchError } from "@medusajs/js-sdk"
|
|
import { sdk } from "../../lib/client"
|
|
import { HttpTypes } from "@medusajs/types"
|
|
|
|
export const useSignInWithEmailPass = (
|
|
options?: UseMutationOptions<
|
|
string,
|
|
FetchError,
|
|
HttpTypes.AdminSignUpWithEmailPassword
|
|
>
|
|
) => {
|
|
return useMutation({
|
|
mutationFn: (payload) => sdk.auth.login("user", "emailpass", payload),
|
|
onSuccess: async (data, variables, context) => {
|
|
options?.onSuccess?.(data, variables, context)
|
|
},
|
|
...options,
|
|
})
|
|
}
|
|
|
|
export const useSignUpWithEmailPass = (
|
|
options?: UseMutationOptions<
|
|
string,
|
|
FetchError,
|
|
HttpTypes.AdminSignInWithEmailPassword
|
|
>
|
|
) => {
|
|
return useMutation({
|
|
mutationFn: (payload) => sdk.auth.register("user", "emailpass", payload),
|
|
onSuccess: async (data, variables, context) => {
|
|
options?.onSuccess?.(data, variables, context)
|
|
},
|
|
...options,
|
|
})
|
|
}
|
|
|
|
export const useResetPasswordForEmailPass = (
|
|
options?: UseMutationOptions<void, FetchError, { email: string }>
|
|
) => {
|
|
return useMutation({
|
|
mutationFn: (payload) =>
|
|
sdk.auth.resetPassword("user", "emailpass", {
|
|
identifier: payload.email,
|
|
}),
|
|
onSuccess: async (data, variables, context) => {
|
|
options?.onSuccess?.(data, variables, context)
|
|
},
|
|
...options,
|
|
})
|
|
}
|
|
|
|
export const useLogout = (options?: UseMutationOptions<void, FetchError>) => {
|
|
return useMutation({
|
|
mutationFn: () => sdk.auth.logout(),
|
|
...options,
|
|
})
|
|
}
|
|
|
|
export const useUpdateProviderForEmailPass = (
|
|
options?: UseMutationOptions<void, FetchError, { password: string }>
|
|
) => {
|
|
return useMutation({
|
|
mutationFn: (payload) =>
|
|
sdk.auth.updateProvider("user", "emailpass", payload),
|
|
onSuccess: async (data, variables, context) => {
|
|
options?.onSuccess?.(data, variables, context)
|
|
},
|
|
...options,
|
|
})
|
|
}
|