0

I am getting a server error(POST http://localhost:3000/create-users 500 (Internal Server Error)) every time i try to use the createUser function included with Clerk Authentication's Javascript Backend SDK. When commenting out the createUser function part, the function runs successfully. I'm wondering if the javascript backend sdk is only available in paid versions?? as I am using the free one for development purposes. Or can anyone see what i'm doing wrong?

Here is the backend code in my NextJS API Route

    import {clerkClient} from '@clerk/nextjs/server';
    import { NextResponse } from 'next/server';


    export async function POST(request) {
    try{
      const { emailAddress, firstName, lastName } = await request.json();
        if(emailAddress){
          const user = await clerkClient.users.createUser({
            emailAddress: [emailAddress],
            password: "wordpass",
            firstName: firstName,
            lastName: lastName,
          });
        }
      console.log(firstName, lastName, emailAddress);
      return NextResponse.json({ user });
     }catch(err){
    //console.log(err,"something went wrong")
    return NextResponse.json({ err: 'Failed to create user' }, { status: 500 });
     }
    }

and the function making the call on the client component:

      const addEmployeeHandler = async (e) => {
        e.preventDefault()
        try{
        const response = await fetch('/create-users', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                firstName: firstName, 
                lastName: lastName, 
                emailAddress: email
               })
            });
            if(!response.ok){
                throw new Error('failed to create user')
            }
            const data = await response.json()
            console.log(response, "successfully added employee", data)
        }catch(err){
            console.log(err, "something went wrong")
        }

Thank you to anyone who might be able to help.

0