Skip to content

Commit

Permalink
Add LogSnag integration for tracking role changes in users.astro
Browse files Browse the repository at this point in the history
  • Loading branch information
kcoderhtml committed Apr 29, 2024
1 parent 2a95c89 commit 2fee640
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/pages/users.astro
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ if (!session) {
});
}
import { LogSnag } from "logsnag";
const logsnag = new LogSnag({
token: "f269dd8e8ec57f9a73737e76c5e0024a",
project: "magicsnap",
});
import { db, User } from "astro:db";
import { like } from "astro:db";
Expand All @@ -55,6 +62,14 @@ if (Astro.request.method === "POST") {
const role = data.get("selected") as string;
if ((role === "admin" || role === "user" || role === "guest") && userId !== session.user.id) {
await db.update(User).set({ role }).where(like(User.userId, userId));
await logsnag.track({
channel: "actions",
event: "role_change",
description: `User ${session.user.name} changed the role of user ${userId} to ${role}`,
icon: "🛡️",
user_id: session.user.id,
});
} else {
error = "You cannot change your own role.";
}
Expand Down

0 comments on commit 2fee640

Please sign in to comment.