const $post = api.auth.signin.request.$post;
const signInRequestMutation = useMutation<
InferResponseType<typeof $post>,
Error,
InferRequestType<typeof $post>["json"]
>({
mutationFn: async (data) => {
const res = await $post({ json: data });
if (!res.ok) {
throw new Error("An error occurred");
}
// Should return:
{
success: true,
user: { //User data }
}
const response = await res.json();
return response;
},
onSuccess: (data) => {
// Only data.success is typed as its also in my 400 res
console.log(data.user)
},
onError: (error) => {
console.log(error);
},
});
const $post = api.auth.signin.request.$post;
const signInRequestMutation = useMutation<
InferResponseType<typeof $post>,
Error,
InferRequestType<typeof $post>["json"]
>({
mutationFn: async (data) => {
const res = await $post({ json: data });
if (!res.ok) {
throw new Error("An error occurred");
}
// Should return:
{
success: true,
user: { //User data }
}
const response = await res.json();
return response;
},
onSuccess: (data) => {
// Only data.success is typed as its also in my 400 res
console.log(data.user)
},
onError: (error) => {
console.log(error);
},
});