Edits history of script submission #12020 for ' Lock a user (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Lock a user
     * Marks the given user as locked, which means they are not allowed to sign in again until the lock expires.
    Lock duration can be configured in the instance's restrictions settings.
     */
    export async function main(auth: Clerk, user_id: string) {
      const url = new URL(`https://api.clerk.com/v1/users/${user_id}/lock`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago