Edits history of script submission #11962 for ' Create a new active session (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Create a new active session
     * Create a new active session for the provided user ID.
    
    This operation is only available for Clerk Development instances.
     */
    export async function main(auth: Clerk, body: { user_id?: string }) {
      const url = new URL(`https://api.clerk.com/v1/sessions`);
    
      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