fix: rework sessions

This commit is contained in:
David Nguyen
2025-02-17 22:46:36 +11:00
parent 1ed1cb0773
commit 5fc724b247
57 changed files with 1512 additions and 1446 deletions

View File

@ -3,7 +3,6 @@ import { useEffect } from 'react';
import posthog from 'posthog-js';
import { useLocation, useSearchParams } from 'react-router';
import { useOptionalSession } from '@documenso/lib/client-only/providers/session';
import { extractPostHogConfig } from '@documenso/lib/constants/feature-flags';
export function PostHogPageview() {
@ -12,19 +11,20 @@ export function PostHogPageview() {
const { pathname } = useLocation();
const [searchParams] = useSearchParams();
const { user } = useOptionalSession();
// const { sessionData } = useOptionalSession();
// const user = sessionData?.user;
if (typeof window !== 'undefined' && postHogConfig) {
posthog.init(postHogConfig.key, {
api_host: postHogConfig.host,
disable_session_recording: true,
loaded: () => {
if (user) {
posthog.identify(user.email ?? user.id.toString());
} else {
posthog.reset();
}
},
// loaded: () => {
// if (user) {
// posthog.identify(user.email ?? user.id.toString());
// } else {
// posthog.reset();
// }
// },
custom_campaign_params: ['src'],
});
}

View File

@ -1,14 +1,16 @@
import { createContext, useContext } from 'react';
import React from 'react';
import type { TGetTeamByUrlResponse } from '@documenso/lib/server-only/team/get-team';
import type { TGetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
type TeamProviderValue = TGetTeamsResponse[0];
interface TeamProviderProps {
children: React.ReactNode;
team: TGetTeamByUrlResponse;
team: TeamProviderValue;
}
const TeamContext = createContext<TGetTeamByUrlResponse | null>(null);
const TeamContext = createContext<TeamProviderValue | null>(null);
export const useCurrentTeam = () => {
const context = useContext(TeamContext);