Next.js Discord

Discord Forum

api/register is internal error 500

Unanswered
Finnish Spitz posted this in #help-forum
Open in Discord
Finnish SpitzOP
before my api for register is going ok, i can add user, but after some hour my localhost/api/register is crash

7 Replies

Please provide some code
Finnish SpitzOP
my handleForm
const handleFormSubmit = async (e: any) => {
    e.preventDefault();
    const passwordHased = await hash(password, 12);

    try {
      const { data, error } = await supabase.auth.signUp({
        email,
        password: passwordHased,
      });

      console.log(data.user);
      console.log(data.user?.email);
      console.log(JSON.stringify({ email, password: passwordHased }));

      await fetch("/api/register", {
        method: "POST",
        body: JSON.stringify({ email, password: passwordHased }),
        headers: {
          "Content-Type": "application/json",
        },
      });

      if (error) {
        alert("User have been registrated before!");
      }
    } catch (error) {
      alert("Something went wront, Can not registration");
    }
  };
my registerRoute
export async function POST(request) {

  try {
    const res = await request.json()
    
    const saveUser = await prisma.User.create({
      data: res,
    });
    return NextResponse.json(saveUser)
  } 
  
  catch (error) {
    // res.status(400).json({ message: " Something went wrong" });
  }
}
i want a user that have registrated will store in db posgrate with prisma