Szymon
Szymon
TtRPC
Created by Szymon on 11/23/2024 in #❓-help
onSuccess and onError in one time
redirect works only with server side 🙈
6 replies
TtRPC
Created by Szymon on 11/23/2024 in #❓-help
onSuccess and onError in one time
and not redirect
6 replies
TtRPC
Created by Szymon on 11/23/2024 in #❓-help
onSuccess and onError in one time
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 };
}),
6 replies
TtRPC
Created by Szymon on 11/23/2024 in #❓-help
onSuccess and onError in one time
6 replies