feat(auth): integrate PostHog for user identification and tracking

This commit is contained in:
Sahaj Jain
2025-04-28 23:08:29 +05:30
parent 68f857e627
commit d69b84b290
2 changed files with 21 additions and 1 deletions
+18 -1
View File
@@ -5,6 +5,7 @@ import { useAuthStore } from "@/store/auth-store";
import { useEffect } from "react";
import { authClient } from "@/lib/auth-client";
import { executePostLoginAction } from "@/hooks/use-post-login-action";
import { usePostHog } from "posthog-js/react";
export function AuthDialogWrapper() {
const {
@@ -15,17 +16,33 @@ export function AuthDialogWrapper() {
clearPostLoginAction,
} = useAuthStore();
const { data: session } = authClient.useSession();
const posthog = usePostHog();
useEffect(() => {
if (isOpen && session) {
closeAuthDialog();
}
if (session && session.user && session.user.email) {
// Identify user with PostHog
posthog.identify(session.user.email, {
name: session.user.name,
email: session.user.email,
});
}
if (session && postLoginAction) {
executePostLoginAction(postLoginAction);
clearPostLoginAction();
}
}, [session, isOpen, closeAuthDialog, postLoginAction, clearPostLoginAction]);
}, [
session,
isOpen,
closeAuthDialog,
postLoginAction,
clearPostLoginAction,
posthog,
]);
return (
<AuthDialog
+3
View File
@@ -15,10 +15,12 @@ import { AnimatePresence, motion } from "motion/react";
import { Loader2 } from "lucide-react";
import Link from "next/link";
import { useAuthStore } from "@/store/auth-store";
import { usePostHog } from "posthog-js/react";
export function UserProfileDropdown() {
const { data: session, isPending } = authClient.useSession();
const { openAuthDialog } = useAuthStore();
const posthog = usePostHog();
return (
<AnimatePresence mode="wait">
@@ -91,6 +93,7 @@ export function UserProfileDropdown() {
</DropdownMenuItem>
<DropdownMenuItem
onClick={async () => {
posthog.reset();
await authClient.signOut();
}}
>