feat: migrate nextjs to rr7

This commit is contained in:
David Nguyen
2025-01-02 15:33:37 +11:00
parent 9183f668d3
commit 383b5f78f0
898 changed files with 31175 additions and 24615 deletions

View File

@ -0,0 +1,45 @@
import { createContext, useContext } from 'react';
import React from 'react';
import type { SessionUser } from '@documenso/auth/server/lib/session/session';
import type { Session } from '@documenso/prisma/client';
import type { TGetTeamByUrlResponse } from '../../server-only/team/get-team';
import type { TGetTeamsResponse } from '../../server-only/team/get-teams';
export type AppSession = {
session: Session;
user: SessionUser;
currentTeam: TGetTeamByUrlResponse | null;
teams: TGetTeamsResponse;
};
interface SessionProviderProps {
children: React.ReactNode;
session: AppSession | null;
}
const SessionContext = createContext<AppSession | null>(null);
export const useSession = () => {
const context = useContext(SessionContext);
if (!context) {
throw new Error('useSession must be used within a SessionProvider');
}
return context;
};
export const useOptionalSession = () => {
return (
useContext(SessionContext) || {
user: null,
session: null,
}
);
};
export const SessionProvider = ({ children, session }: SessionProviderProps) => {
return <SessionContext.Provider value={session}>{children}</SessionContext.Provider>;
};