mirror of
https://github.com/jnsahaj/tweakcn.git
synced 2026-09-24 23:31:41 +08:00
feat(auth): integrate PostHog for user identification and tracking
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user