Skip to content

Protecting actions

Protecting actions

Protecting actions is simple with Kilpi. You have two options: use the throw -based protection API or the manual protection API. Read more about the APIs.

Examples

With throw -based API.

export async function deleteComment(commentId: string) {
await Kilpi.authorize("comments:delete", { commentId });
await db.deleteComment(commentId);
}

With manual API.

export async function deleteComment(commentId: string) {
if (!(await Kilpi.isAuthorized("comments:delete", { commentId }))) {
return;
}
await db.deleteComment(commentId);
}