#is it correct to have an error like this ?

1 messages · Page 1 of 1 (latest)

onyx spear
#

I want to handle errors, for example when executing this mutation an error appears

"use client";
etc
const mutationAdd = trpc.user.addUser.useMutation({
    onSuccess: async (data) => {
      await utils.user.getUsers.refetch();
      router.push("/admin/all-employees");
    },
    onError: (error) => {
      toast({
        variant: "destructive",
        action: <ToastAction altText="Try again">{error.message}</ToastAction>,
      });
      return;
    },
  });

server router

 addUser: publicProcedure
    .input(
      z.object({
        username: z.string(),
        name: z.string(),
        email: z.string().email(),
        password: z
          .string()
          .min(5, "password should be at least 5 digits long."),
        role: z.string(),
      })
    )
    .mutation(async ({ input }) => {
      const newUser = await auth.api.createUser({
        headers: await headers(),
        body: {
          name: input.name,
          email: input.email,
          password: input.password,
          role: input.role,
          data: {
            username: input.username,
          },
        },
      });
      return newUser;
    }),```
short tinselBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)