File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed
Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 11import AppShell from "@/components/app-shell" ;
2+ import PostHogIdentifier from "@/providers/posthog-identifier" ;
23import AuthorizedApolloWrapper from "@/providers/use-apollo.rsc" ;
34import ProtectedRoute from "@/providers/use-protected-route" ;
45import { unstable_ViewTransition as ViewTransition } from "react" ;
@@ -7,6 +8,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
78 return (
89 < ProtectedRoute >
910 < AuthorizedApolloWrapper >
11+ < PostHogIdentifier />
1012 < AppShell >
1113 < div className = "mx-auto w-full max-w-7xl flex-1 p-3" >
1214 < ViewTransition name = "app-content" >
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { useEffect } from "react" ;
4+
5+ import posthog from "posthog-js" ;
6+
7+ export default function PostHogResetter ( ) {
8+ useEffect ( ( ) => {
9+ posthog . reset ( ) ;
10+ } , [ ] ) ;
11+
12+ return null ;
13+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import DoYouKnowSkeleton from "./_components/do-you-know/skeleton";
77import GithubLink from "./_components/github-link" ;
88import { LoginForm } from "./_components/login-form" ;
99import { UpstreamStatus , UpstreamStatusPlaceholder } from "./_components/status" ;
10+ import PostHogResetter from "./_components/posthog-resetter" ;
1011
1112export const metadata : Metadata = {
1213 title : "登入" ,
@@ -21,6 +22,9 @@ export default async function LoginPage() {
2122 lg:px-14 lg:py-8
2223 ` }
2324 >
25+ { /* Reset the session on the login page */ }
26+ < PostHogResetter />
27+
2428 < div className = "flex max-w-sm flex-1 flex-col justify-center gap-6" >
2529 < Link
2630 href = "/"
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import useUser from "@/hooks/use-user" ;
4+ import posthog from "posthog-js" ;
5+ import { useEffect } from "react" ;
6+
7+ /**
8+ * Identify the current user if they are logged in.
9+ * If they are not logged in, reset the posthog session.
10+ */
11+ export default function PostHogIdentifier ( ) {
12+ const { user } = useUser ( ) ;
13+
14+ useEffect ( ( ) => {
15+ if ( user ) {
16+ posthog . identify ( user . id , {
17+ name : user . name ,
18+ email : user . email ,
19+ } ) ;
20+ }
21+ } , [ user ] ) ;
22+
23+ return null ;
24+ }
You can’t perform that action at this time.
0 commit comments