0

Create a JWT template

by
Published Apr 8, 2025

Create a new JWT template

Script clerk Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Clerk = {
3
  apiKey: string;
4
};
5
/**
6
 * Create a JWT template
7
 * Create a new JWT template
8
 */
9
export async function main(
10
  auth: Clerk,
11
  body: {
12
    name?: string;
13
    claims?: {};
14
    lifetime?: number;
15
    allowed_clock_skew?: number;
16
    custom_signing_key?: false | true;
17
    signing_algorithm?: string;
18
    signing_key?: string;
19
  },
20
) {
21
  const url = new URL(`https://api.clerk.com/v1/jwt_templates`);
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.apiKey,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37