tRPC mutation and data

Hi, so with tRPC I'm creating an account, which I have some checks on the function to see if an account with the same email already exists. With it, I'm returning a status code and message, and the same for if a user is successfully created. However, I am having trouble with obtaining this data on the frontend. I will either get a null/undefined object, or I will get the data but it will be from the last function call, not the current one.

Currently my code looks something like this:
// frontend

mutation.mutate({
  email: email,
  name: username,
  password: password,
});
console.log(mutation.data);


// backend
if (exists) {
  return {
    status: "409",
    message: "A user with that email address already exists",
  };
}

// create the user
return {
  status: "201", 
  message: "User created successfully",
};
Was this page helpful?