Szymon
Szymon2mo ago

onSuccess and onError in one time

Hi! I have onError and onSuccess execute in one time
2 Replies
Szymon
SzymonOP2mo ago
Szymon
SzymonOP2mo 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 🙈

Did you find this page helpful?