Handling 500 Internal Server Error on tRPC Mutation in a Next.js T3 Stack Application

When calling the auth.UserChecker mutation from my React frontend, the server responds with a 500 error. The mutation is intended to check user credentials during login.
Also, the register page is the same thing as a login page, but does just different input this is the Hum getting there

List of tools being used

  • Next.js
  • NextAuth.js
  • Prisma
  • Tailwind CSS
  • tRPC

Location of error occurred
trpc query : Src -> server -> api -> routers -> auth.ts

Being used : Src -> components -> auth -> [ register.tsx. | login.tsx ]

The rest of the T3 app configuration is default

https://github.com/gaveone/expo-A

login.tsx

"use client";
import { api } from "@/trpc/react";
function Login() {
  const { toast } = useToast();
  const UserChecker =  api.auth.UserChecker.useMutation({
    onSuccess: (response) => {
      console.log("Mutation successful", response);
      // Handle successful mutation, e.g., redirect or update UI
    },
    onError: (error) => {
      console.log("Mutation error", error);
      toast({
        variant: "destructive",
        title: "Error", 
        
        description: "An error occurred during login."
      });
    }
  })
  const [user, setNewUser] = useState({
    email: "",
    password: "",
  });
  const loginForm = z.object({
    email: z
      .string()
      .min(1, { message: "This field has to be filled." })
      .email("This is not a valid email."),
    password: z.string().min(1, { message: "This field has to be filled" }),
  });

   async function LoginFormSubmet() {
    const validUser = loginForm.safeParse(user);
   
      if (validUser.data) {
        console.log("4");

        const Data = validUser.data;
        UserChecker.mutate(Data)
          
      }
    
  }
  return (
    <>
      
       Input will be here.

      <Button
        
        className=" relative w-48"
        onClick={(e) => {
          e.preventDefault();
          LoginFormSubmet();
        }}
      >
        {" "}
        Register
      </Button>
     
    </>
  );
}

export default Login;

trpc query

import { object, z } from "zod";
import bcrypt from 'bcryptjs';

import {
  createTRPCRouter,
  protectedProcedure,
  publicProcedure,
} from "@/server/api/trpc";

export const authRouter = createTRPCRouter({
    UserChecker:publicProcedure.input(z.object({email:z.string() ,password:z.string()}))
    .mutation(async({ctx,input})=>{
        console.log(input);
        return JSON.parse(JSON.stringify({data:"password"}));

    }),
    makeNewUser:publicProcedure.input(z.object({
        name: z.string().min(1 ,{message:"This field has to be filled."}),
        dateOfBirth:z.string().min(1 ,{message:"This field has to be filled."}),
        email:z.string().min(1, { message: "This field has to be filled." }).email("This is not a valid email."),
        password:z.string().min(5 ,{message:"password  must be at least 5 characters"}),
        confirmPassword:z.string()

    })).mutation( async({ctx ,input})=>{
        const FindUser = await ctx.db.user.findUnique({
            where:{
                email:input.email
            }
        })

        if(FindUser){return{error:"this user exists"}}
        if(!FindUser){
            const salt = await bcrypt.genSalt(10);
            const passwordHash =  await bcrypt.hash(input.password, salt);
        const newUser = await ctx.db.user.create({
            data:{
                name:input.name,
                email:input.email,
                dateOfBirth:input.dateOfBirth,
                password:passwordHash
            }
        })

        }


    }),
    findUser:publicProcedure.input(z.object({
        email:z.string().min(1, { message: "This field has to be filled." }).email("This is not a valid email.")
    })).query(async({ ctx ,input}) =>{
        return ctx.db.user.findUnique({where:{email:input.email}})
    }),

    
    findUserValidation:publicProcedure.input(z.object({
        email:z.string().min(1, { message: "This field has to be filled." }).email("This is not a valid email."),
        password:z.string(),

    })).mutation(async({ ctx ,input}) =>{
        const FoundUser = await ctx.db.user.findUnique({where:{email:input.email}})
        if(!FoundUser){return {error:"user Does not exist"}}
        const CheckPassword = await bcrypt.compare(input.password ,FoundUser.password)
        if(!CheckPassword){return{error:"user Does not exist"}}
        return{input}
    })
 
});

New contributor

OGZY MMO is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật