mirror of
https://github.com/documenso/documenso.git
synced 2025-11-24 21:51:40 +10:00
wip
This commit is contained in:
29
apps/remix/app/providers/auth.tsx
Normal file
29
apps/remix/app/providers/auth.tsx
Normal file
@ -0,0 +1,29 @@
|
||||
import { createContext, useContext } from 'react';
|
||||
import React from 'react';
|
||||
|
||||
import type { Session, User } from '@prisma/client';
|
||||
|
||||
interface AuthProviderProps {
|
||||
children: React.ReactNode;
|
||||
session: Session;
|
||||
user: User;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<{
|
||||
user: User; // Todo: Exclude password
|
||||
session: Session;
|
||||
} | null>(null);
|
||||
|
||||
export const useAuth = () => {
|
||||
const context = useContext(AuthContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error('useAuth must be used within a AuthProvider');
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
export const AuthProvider = ({ children, session, user }: AuthProviderProps) => {
|
||||
return <AuthContext.Provider value={{ session, user }}>{children}</AuthContext.Provider>;
|
||||
};
|
||||
10
apps/remix/app/providers/next-theme.tsx
Normal file
10
apps/remix/app/providers/next-theme.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
import { ThemeProvider as NextThemesProvider } from 'next-themes';
|
||||
import type { ThemeProviderProps } from 'next-themes/dist/types';
|
||||
|
||||
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
|
||||
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
|
||||
}
|
||||
13
apps/remix/app/providers/plausible.tsx
Normal file
13
apps/remix/app/providers/plausible.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import NextPlausibleProvider from 'next-plausible';
|
||||
|
||||
export type PlausibleProviderProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export const PlausibleProvider = ({ children }: PlausibleProviderProps) => {
|
||||
return <NextPlausibleProvider domain="documenso.com">{children}</NextPlausibleProvider>;
|
||||
};
|
||||
51
apps/remix/app/providers/posthog.tsx
Normal file
51
apps/remix/app/providers/posthog.tsx
Normal file
@ -0,0 +1,51 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { getSession } from 'next-auth/react';
|
||||
import posthog from 'posthog-js';
|
||||
import { useLocation, useSearchParams } from 'react-router';
|
||||
|
||||
import { extractPostHogConfig } from '@documenso/lib/constants/feature-flags';
|
||||
|
||||
export function PostHogPageview() {
|
||||
const postHogConfig = extractPostHogConfig();
|
||||
|
||||
const { pathname } = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
if (typeof window !== 'undefined' && postHogConfig) {
|
||||
posthog.init(postHogConfig.key, {
|
||||
api_host: postHogConfig.host,
|
||||
disable_session_recording: true,
|
||||
loaded: () => {
|
||||
getSession()
|
||||
.then((session) => {
|
||||
if (session) {
|
||||
posthog.identify(session.user.email ?? session.user.id.toString());
|
||||
} else {
|
||||
posthog.reset();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Do nothing.
|
||||
});
|
||||
},
|
||||
custom_campaign_params: ['src'],
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!postHogConfig || !pathname) {
|
||||
return;
|
||||
}
|
||||
|
||||
let url = window.origin + pathname;
|
||||
if (searchParams && searchParams.toString()) {
|
||||
url = url + `?${searchParams.toString()}`;
|
||||
}
|
||||
posthog.capture('$pageview', {
|
||||
$current_url: url,
|
||||
});
|
||||
}, [pathname, searchParams, postHogConfig]);
|
||||
|
||||
return null;
|
||||
}
|
||||
29
apps/remix/app/providers/team.tsx
Normal file
29
apps/remix/app/providers/team.tsx
Normal file
@ -0,0 +1,29 @@
|
||||
import { createContext, useContext } from 'react';
|
||||
import React from 'react';
|
||||
|
||||
import type { TGetTeamByIdResponse } from '@documenso/lib/server-only/team/get-team';
|
||||
|
||||
interface TeamProviderProps {
|
||||
children: React.ReactNode;
|
||||
team: TGetTeamByIdResponse;
|
||||
}
|
||||
|
||||
const TeamContext = createContext<TGetTeamByIdResponse | null>(null);
|
||||
|
||||
export const useCurrentTeam = () => {
|
||||
const context = useContext(TeamContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error('useCurrentTeam must be used within a TeamProvider');
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
export const useOptionalCurrentTeam = () => {
|
||||
return useContext(TeamContext);
|
||||
};
|
||||
|
||||
export const TeamProvider = ({ children, team }: TeamProviderProps) => {
|
||||
return <TeamContext.Provider value={team}>{children}</TeamContext.Provider>;
|
||||
};
|
||||
Reference in New Issue
Block a user