Edits history of script submission #11968 for ' Create a session token (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Create a session token
     * Creates a session JSON Web Token (JWT) based on a session.
     */
    export async function main(
      auth: Clerk,
      session_id: string,
      body: { expires_in_seconds?: number },
    ) {
      const url = new URL(`https://api.clerk.com/v1/sessions/${session_id}/tokens`);
    
      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