Szymon
Szymon2w ago

onSuccess and onError in one time

Hi! I have onError and onSuccess execute in one time
2 Replies
Szymon
SzymonOP2w ago
signUp: publicProcedure.input(SignUpSchema).mutation(async ({ input }) => {
const passwordHash = hashSync(input.password, 10);

const isEmailTaken = await userModel.exists({ email: input.email });
if (isEmailTaken) {
console.log("Email is already taken");
throw new TRPCError({
code: "BAD_REQUEST",
message: "Email is already taken",
});
}

await userModel.insertMany([
{
email: input.email,
password: passwordHash,
firstName: input.firstName,
lastName: input.lastName,
},
]);
return { signedUp: true };
}),
signUp: publicProcedure.input(SignUpSchema).mutation(async ({ input }) => {
const passwordHash = hashSync(input.password, 10);

const isEmailTaken = await userModel.exists({ email: input.email });
if (isEmailTaken) {
console.log("Email is already taken");
throw new TRPCError({
code: "BAD_REQUEST",
message: "Email is already taken",
});
}

await userModel.insertMany([
{
email: input.email,
password: passwordHash,
firstName: input.firstName,
lastName: input.lastName,
},
]);
return { signedUp: true };
}),
and not redirect redirect works only with server side 🙈