0

Create a new active session

by
Published Apr 8, 2025

Create a new active session for the provided user ID. This operation is only available for Clerk Development instances.

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 new active session
7
 * Create a new active session for the provided user ID.
8

9
This operation is only available for Clerk Development instances.
10
 */
11
export async function main(auth: Clerk, body: { user_id?: string }) {
12
  const url = new URL(`https://api.clerk.com/v1/sessions`);
13

14
  const response = await fetch(url, {
15
    method: "POST",
16
    headers: {
17
      "Content-Type": "application/json",
18
      Authorization: "Bearer " + auth.apiKey,
19
    },
20
    body: JSON.stringify(body),
21
  });
22
  if (!response.ok) {
23
    const text = await response.text();
24
    throw new Error(`${response.status} ${text}`);
25
  }
26
  return await response.json();
27
}
28