Edits history of script submission #11965 for ' Create a new user (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Create a new user
     * Creates a new user. Your user management settings determine how you should setup your user model.
    
    Any email address and phone number created using this method will be marked as verified.
    
    Note: If you are performing a migration, check out our guide on [zero downtime migrations](https://clerk.com/docs/deployments/migrate-overview).
    
    A rate limit rule of 20 requests per 10 seconds is applied to this endpoint.
     */
    export async function main(
      auth: Clerk,
      body: {
        external_id?: string;
        first_name?: string;
        last_name?: string;
        email_address?: string[];
        phone_number?: string[];
        web3_wallet?: string[];
        username?: string;
        password?: string;
        password_digest?: string;
        password_hasher?: string;
        skip_password_checks?: false | true;
        skip_password_requirement?: false | true;
        totp_secret?: string;
        backup_codes?: string[];
        public_metadata?: {};
        private_metadata?: {};
        unsafe_metadata?: {};
        delete_self_enabled?: false | true;
        legal_accepted_at?: string;
        skip_legal_checks?: false | true;
        create_organization_enabled?: false | true;
        create_organizations_limit?: number;
        created_at?: string;
      },
    ) {
      const url = new URL(`https://api.clerk.com/v1/users`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago