Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify users based on clerk id #179

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/frontend/src/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export function PHProvider({
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY || "", {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: 'identified_only',
capture_pageview: false // Disable automatic pageview capture, as we capture manually
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
session_recording: {
maskAllInputs: false,
maskInputOptions: {
password: true,
}
}
})
}, []);

Expand Down
13 changes: 12 additions & 1 deletion apps/frontend/src/components/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SideNav } from "./SideNav";
import Link from "./Link";
import { useAuth } from "@clerk/nextjs";
import { userSlice } from "~/app/user";
import { usePostHog } from "posthog-js/react";

type Props = {
sidebar?: React.ReactNode;
Expand All @@ -23,7 +24,7 @@ export const Page = ({ sidebar, content, activePage }: Props) => {
);
const dispatch = useAppDispatch();

const { isLoaded, userId, sessionId, getToken } = useAuth();
const { isLoaded, isSignedIn, userId, sessionId, getToken } = useAuth();

useEffect(() => {
if (isLoaded && userId && sessionId) {
Expand All @@ -50,6 +51,16 @@ export const Page = ({ sidebar, content, activePage }: Props) => {
}
}, [dispatch, loggedIn, modalShown]);

const posthog = usePostHog();

useEffect(() => {
if (isSignedIn && userId) {
posthog?.identify(userId);
} else {
posthog?.reset();
}
}, [posthog, isSignedIn, userId]);

return (
<div className="accent-blue-600 dark:accent-blue-800">
<LoginModal />
Expand Down
Loading