🔨 Use email as distinct id

This commit is contained in:
Luke Vella 2024-01-26 12:45:48 +07:00
parent 1e4fe071aa
commit 63c6c4f92d

View file

@ -162,6 +162,7 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
callbacks: { callbacks: {
async signIn({ user, email, account, profile }) { async signIn({ user, email, account, profile }) {
const posthog = PostHogClient(); const posthog = PostHogClient();
const distinctId = user.email ?? user.id;
// prevent sign in if email is not verified // prevent sign in if email is not verified
if ( if (
profile && profile &&
@ -169,7 +170,7 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
profile.email_verified === false profile.email_verified === false
) { ) {
posthog?.capture({ posthog?.capture({
distinctId: user.id, distinctId,
event: "login failed", event: "login failed",
properties: { properties: {
reason: "email not verified", reason: "email not verified",
@ -209,7 +210,7 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
} }
posthog?.capture({ posthog?.capture({
distinctId: user.id, distinctId,
event: "login", event: "login",
properties: { properties: {
method: account?.provider, method: account?.provider,