23 lines
861 B
TypeScript
23 lines
861 B
TypeScript
import { useInject } from '@/lib/di/hooks/useInject';
|
|
import { AUTH_SERVICE_TOKEN } from '@/lib/di/tokens';
|
|
import { ApiError } from '@/lib/gateways/api/base/ApiError';
|
|
import type { SignupParamsDTO } from '@/lib/types/generated/SignupParamsDTO';
|
|
import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
|
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
|
|
|
export function useSignup(
|
|
options?: Omit<UseMutationOptions<SessionViewModel, ApiError, SignupParamsDTO>, 'mutationFn'>
|
|
) {
|
|
const authService = useInject(AUTH_SERVICE_TOKEN);
|
|
|
|
return useMutation<SessionViewModel, ApiError, SignupParamsDTO>({
|
|
mutationFn: async (params) => {
|
|
const result = await authService.signup(params);
|
|
if (result.isErr()) {
|
|
throw result.getError();
|
|
}
|
|
return result.unwrap();
|
|
},
|
|
...options,
|
|
});
|
|
} |