Skip to content

Commit

Permalink
Merge pull request #5274 from systeminit/adding-workspace-owner
Browse files Browse the repository at this point in the history
feat(auth-api): Adding workspace owner to tokens posthog events
  • Loading branch information
johnrwatson authored Jan 16, 2025
2 parents 87fdb91 + 9775c90 commit 7e0da6d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bin/auth-api/src/routes/auth_token.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { authorizeWorkspaceRoute } from "./workspace.routes";
import { ApiError } from "../lib/api-error";
import { tracker } from "../lib/tracker";
import { getUserById } from "../services/users.service";
import { router } from ".";

// get all authTokens for the given workspace
Expand Down Expand Up @@ -68,13 +69,17 @@ router.post("/workspaces/:workspaceId/authTokens", async (ctx) => {
// And decode it to get the generated values (such as expiration)
const authToken = await registerAuthToken(name, await decodeSdfAuthToken(token));

const workspaceOwner = await getUserById(workspace.creatorUserId)!;

tracker.trackEvent(authUser, "workspace_api_token_created", {
workspaceId: workspace.id,
workspaceName: workspace.displayName,
workspaceOwner: workspaceOwner?.email,
tokenName: name,
tokenCreated: authToken.createdAt,
tokenExpires: authToken.expiresAt,
initiatedAt: authUser.email,
initiatedBy: authUser.email,
tokenAction: "created",
});

ctx.body = { authToken, token };
Expand All @@ -92,13 +97,17 @@ router.post("/workspaces/:workspaceId/authTokens/:authTokenId/revoke", async (ct

await updateAuthToken(authToken.id, { revokedAt: new Date() });

const workspaceOwner = await getUserById(workspace.creatorUserId)!;

tracker.trackEvent(authUser, "workspace_api_token_revoked", {
workspaceId: workspace.id,
workspaceName: workspace.displayName,
workspaceOwner: workspaceOwner?.email,
tokenName: authToken.name,
tokenCreated: authToken.createdAt,
tokenRevoked: new Date(),
initiatedAt: authUser.email,
initiatedBy: authUser.email,
tokenAction: "revoked",
});

ctx.body = { authToken };
Expand Down

0 comments on commit 7e0da6d

Please sign in to comment.