//native
type Clerk = {
apiKey: string;
};
/**
* Create actor token
* Create an actor token that can be used to impersonate the given user.
The `actor` parameter needs to include at least a "sub" key whose value is the ID of the actor (impersonating) user.
*/
export async function main(
auth: Clerk,
body: {
user_id: string;
actor: {};
expires_in_seconds?: number;
session_max_duration_in_seconds?: number;
},
) {
const url = new URL(`https://api.clerk.com/v1/actor_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