Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
📈 Capture logout event + merge set and identify calls (#1211)
Luke Vellaba3008b3f231
diff --git a/apps/web/src/app/components/logout-button.tsx b/apps/web/src/app/components/logout-button.tsxindex 5b3613c6d..c78496dfc 100644--- a/apps/web/src/app/components/logout-button.tsx+++ b/apps/web/src/app/components/logout-button.tsx@@ -1,14 +1,29 @@+"use client";import { Button, ButtonProps } from "@rallly/ui/button";+import { signOut } from "next-auth/react";++import { usePostHog } from "@/utils/posthog";export function LogoutButton({children,+ onClick,...rest}: React.PropsWithChildren<ButtonProps>) {+ const posthog = usePostHog();return (- <form action="/auth/logout" method="POST">- <Button {...rest} type="submit">- {children}- </Button>- </form>+ <Button+ {...rest}+ onClick={async (e) => {+ onClick?.(e);+ posthog?.capture("logout");+ posthog?.reset();+ signOut({+ redirect: true,+ callbackUrl: "/login",+ });+ }}+ >+ {children}+ </Button>);}diff --git a/apps/web/src/contexts/posthog.tsx b/apps/web/src/contexts/posthog.tsxindex 0a6d7bfa5..16b822488 100644--- a/apps/web/src/contexts/posthog.tsx+++ b/apps/web/src/contexts/posthog.tsx@@ -5,6 +5,7 @@ import { PostHogProvider as Provider, usePostHog } from "posthog-js/react";import React from "react";import { useMount } from "react-use";+import { useTranslation } from "@/app/i18n/client";import { useUser } from "@/components/user-provider";import { env } from "@/env";@@ -48,14 +49,18 @@ function usePostHogPageView() {export function PostHogProvider(props: PostHogProviderProps) {const { user } = useUser();+ const { i18n } = useTranslation();+usePostHogPageView();useMount(() => {if (user.email) {- posthog.identify(user.id);- posthog.people.set({- $email: user.email,- $name: user.name,+ posthog.identify(user.id, {+ email: user.email,+ name: user.name,+ tier: user.tier,+ timeZone: user.timeZone,+ locale: i18n.language,});}});diff --git a/apps/web/src/utils/auth.ts b/apps/web/src/utils/auth.tsindex b1065aea6..fc94b382e 100644--- a/apps/web/src/utils/auth.ts+++ b/apps/web/src/utils/auth.ts@@ -174,7 +174,6 @@ const getAuthOptions = (...args: GetServerSessionParams) =>providers: providers,pages: {signIn: "/login",- signOut: "/logout",error: "/auth/error",},events: {@@ -193,12 +192,6 @@ const getAuthOptions = (...args: GetServerSessionParams) =>},});},- signOut({ session }) {- posthog?.capture({- distinctId: session.user.id,- event: "logout",- });- },},callbacks: {async signIn({ user, email, profile }) {