Skip to content

Commit

Permalink
log created user to posthog
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnmclean committed Jan 28, 2025
1 parent 5cef298 commit edc68e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions apps/sovoli.com/src/core/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { db, schema } from "@sovoli/db";
import NextAuth from "next-auth";
import Resend from "next-auth/providers/resend";

import { getPostHogClient } from "../posthog/posthog";

const adapter = DrizzleAdapter(db, {
usersTable: schema.User,
accountsTable: schema.Account,
Expand Down Expand Up @@ -33,6 +35,19 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
};
},
},
events: {
async createUser(message) {
const posthog = getPostHogClient();
posthog.capture({
distinctId: message.user.id ?? "",
event: "User Created",
properties: {
email: message.user.email,
},
});
await posthog.shutdown();
},
},
session: {
strategy: "database",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PostHog } from "posthog-node";

import { env } from "~/env";

export function PostHogClient() {
export function getPostHogClient() {
const posthogClient = new PostHog(env.NEXT_PUBLIC_POSTHOG_KEY, {
host: "https://us.i.posthog.com",
flushAt: 1,
Expand Down

0 comments on commit edc68e6

Please sign in to comment.