Form Data not send to the API

import prisma from "@/app/lib/db";
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import { NextResponse } from "next/server";

export async function POST(request: Request) {
  try {
    const { getUser } = getKindeServerSession();
    const user = await getUser();

    console.log("User session details:", user);

    if (!user || !user.id) {
      console.error("Account Identification Failed: User or User ID is missing");
      throw new Error("Account Identification Failed");
    }

    const { roleName } = await request.json();
    console.log(`Role name received: ${roleName}`);

    if (!roleName || (roleName !== 'Freelancer' && roleName !== 'Client')) {
      console.error("Invalid Role");
      return NextResponse.json({ error: 'Invalid Role' }, { status: 400 });
    }

    const role = await prisma.role.findFirst({
      where: {
        roleName,
      },
    });

    if (!role) {
      console.error("Role not found in database");
      return NextResponse.json({ error: 'Role not found' }, { status: 404 });
    }

    const updatedUser = await prisma.user.update({
      where: {
        id: user.id,
      },
      data: {
        roleId: role.id,
      },
    });

    console.log(`User ${updatedUser.id} role updated to ${roleName}`);

    const redirectUrl = roleName === "Freelancer"
      ? "http://localhost:3000/dashboard/freelancer"
      : "http://localhost:3000/dashboard/client";

    return NextResponse.redirect(redirectUrl);
  } catch (error) {
    if (error instanceof Error) {
      console.error("Error in role selection POST route:", error.message);
      return NextResponse.json({ error: error.message }, { status: 500 });
    } else {
      console.error("Unexpected error in role selection POST route:", error);
      return NextResponse.json({ error: "Unexpected error occurred" }, { status: 500 });
    }
  }
}

'use client';
import React, { useState } from 'react';
import { useRouter } from 'next/navigation';
import { FaUserTie, FaBriefcase } from 'react-icons/fa';

const RoleSelection = () => {
  const [loading, setLoading] = useState(false);
  const router = useRouter();

  const handleRoleSelection = async (role: string) => {
    setLoading(true);
    console.log(`Role selected: ${role}`);
    try {
      const response = await fetch('/api/roleselection', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({ roleName: role }),
      });

      console.log('Fetch response:', response);

      if (response.ok) {
        const redirectUrl = role === 'Freelancer'
          ? '/dashboard/freelancer'
          : '/dashboard/client';
        console.log(`Redirecting to ${redirectUrl}`);
        router.push(redirectUrl);
      } else {
        const errorData = await response.json();
        console.error('Failed to select role', errorData);
      }
    } catch (error) {
      console.error('Error selecting role:', error);
    } finally {
      setLoading(false);
    }
  };

  return (
    <div className="flex flex-col items-center justify-center min-h-screen bg-gray-50">
      <h1 className="text-4xl font-bold text-yellow-500 mb-12">Register As a</h1>
      <div className="grid grid-cols-2 gap-4 w-full max-w-md mx-auto">
        <div
          onClick={() => handleRoleSelection('Freelancer')}
          className="cursor-pointer aspect-square flex flex-col items-center justify-center text-center text-gray-800 bg-white border-2 border-gray-800 rounded-lg shadow-lg hover:bg-yellow-500 hover:text-white transition-all duration-300 ease-in-out transform hover:scale-105"
        >
          <FaUserTie className="text-6xl mb-2" />
          <span className="text-xl font-semibold">Freelancer</span>
        </div>
        <div
          onClick={() => handleRoleSelection('Client')}
          className="cursor-pointer aspect-square flex flex-col items-center justify-center text-center text-gray-800 bg-white border-2 border-gray-800 rounded-lg shadow-lg hover:bg-yellow-500 hover:text-white transition-all duration-300 ease-in-out transform hover:scale-105"
        >
          <FaBriefcase className="text-6xl mb-2" />
          <span className="text-xl font-semibold">Client</span>
        </div>
      </div>
      {loading && <p className="text-yellow-500 mt-4">Loading...</p>}
    </div>
  );
};

export default RoleSelection;

I made Role selection page and when user select the role they need to redirect to the dashbord page according to their selected role. I added the Roleselection page tsx file and route.ts file.
I use nextjs,prisma,supabase and Kinde auth.
when i click the role Freelancer or Client it not redirect to the dashbord. just loading and still in the same page. And when i try POST Request with postman it shows
500 internal server error
“error”: “Account Identification Failed”

Can anyone give me solution for this

New contributor

SamiBro 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