Skip to content

Commit

Permalink
change user modify auth table to more understandable event names (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwong525 authored Mar 3, 2024
1 parent 255fe8e commit b074a55
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions supabase/functions/on_user_modify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ Deno.serve(async (req) => {
let { record, old_record, type } = await req.json();
record = record || old_record;

let event: string | undefined;
// deno-lint-ignore no-explicit-any
const properties: Record<string, any> = { type };
properties["$set"] = properties["$set"] || {};
properties["$set"].email = record.email || undefined;
properties["$set"].created_at = record.created_at;
properties["$set"].last_sign_in_at = record.last_sign_in_at;

posthog.capture({
distinctId: record.id,
event: "user modify auth table",
properties: properties,
});
if (type === "INSERT") {
event = "user signs up";
} else if (
type === "UPDATE" && record.last_sign_in_at !== old_record.last_sign_in_at
) {
event = "user signs in";
} else if (type === "DELETE") {
event = "user deletes account";
}

if (event) {
posthog.capture({
distinctId: record.id,
event,
properties: properties,
});
}

return new Response(null);
});

0 comments on commit b074a55

Please sign in to comment.