mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-28 21:57:23 +02:00
♻️ Add abstractions for tracking server-side events (#1143)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
81d2f2c0bd
commit
d43bc631f1
9 changed files with 69 additions and 12 deletions
|
@ -17,7 +17,7 @@ import EmailProvider from "next-auth/providers/email";
|
|||
import GoogleProvider from "next-auth/providers/google";
|
||||
import { Provider } from "next-auth/providers/index";
|
||||
|
||||
import { PostHogClient } from "@/app/posthog";
|
||||
import { posthog } from "@/app/posthog";
|
||||
import { absoluteUrl } from "@/utils/absolute-url";
|
||||
import { CustomPrismaAdapter } from "@/utils/auth/custom-prisma-adapter";
|
||||
import { mergeGuestsIntoUser } from "@/utils/auth/merge-user";
|
||||
|
@ -176,7 +176,6 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
|
|||
},
|
||||
callbacks: {
|
||||
async signIn({ user, email, account, profile }) {
|
||||
const posthog = PostHogClient();
|
||||
const distinctId = user.email ?? user.id;
|
||||
// prevent sign in if email is not verified
|
||||
if (
|
||||
|
@ -191,7 +190,6 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
|
|||
reason: "email not verified",
|
||||
},
|
||||
});
|
||||
await posthog?.shutdownAsync();
|
||||
return false;
|
||||
}
|
||||
// Make sure email is allowed
|
||||
|
@ -224,6 +222,14 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
|
|||
await mergeGuestsIntoUser(user.id, [session.user.id]);
|
||||
}
|
||||
|
||||
posthog?.identify({
|
||||
distinctId,
|
||||
properties: {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
},
|
||||
});
|
||||
|
||||
posthog?.capture({
|
||||
distinctId,
|
||||
event: "login",
|
||||
|
@ -231,7 +237,6 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
|
|||
method: account?.provider,
|
||||
},
|
||||
});
|
||||
await posthog?.shutdownAsync();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue