diff --git a/apps/web/src/app/(dashboard)/admin/layout.tsx b/apps/web/src/app/(dashboard)/admin/layout.tsx index 3aa47d1a9..a3076a74c 100644 --- a/apps/web/src/app/(dashboard)/admin/layout.tsx +++ b/apps/web/src/app/(dashboard)/admin/layout.tsx @@ -12,7 +12,7 @@ export type AdminSectionLayoutProps = { }; export default async function AdminSectionLayout({ children }: AdminSectionLayoutProps) { - const user = await getRequiredServerComponentSession(); + const { user } = await getRequiredServerComponentSession(); if (!isAdmin(user)) { redirect('/documents'); diff --git a/apps/web/src/app/(dashboard)/documents/[id]/page.tsx b/apps/web/src/app/(dashboard)/documents/[id]/page.tsx index c9d56e454..d44ac2800 100644 --- a/apps/web/src/app/(dashboard)/documents/[id]/page.tsx +++ b/apps/web/src/app/(dashboard)/documents/[id]/page.tsx @@ -30,11 +30,11 @@ export default async function DocumentPage({ params }: DocumentPageProps) { redirect('/documents'); } - const session = await getRequiredServerComponentSession(); + const { user } = await getRequiredServerComponentSession(); const document = await getDocumentById({ id: documentId, - userId: session.id, + userId: user.id, }).catch(() => null); if (!document || !document.documentData) { @@ -50,11 +50,11 @@ export default async function DocumentPage({ params }: DocumentPageProps) { const [recipients, fields] = await Promise.all([ await getRecipientsForDocument({ documentId, - userId: session.id, + userId: user.id, }), await getFieldsForDocument({ documentId, - userId: session.id, + userId: user.id, }), ]); @@ -87,7 +87,7 @@ export default async function DocumentPage({ params }: DocumentPageProps) { diff --git a/apps/web/src/app/(dashboard)/settings/billing/page.tsx b/apps/web/src/app/(dashboard)/settings/billing/page.tsx index 28c8b8122..a5c672971 100644 --- a/apps/web/src/app/(dashboard)/settings/billing/page.tsx +++ b/apps/web/src/app/(dashboard)/settings/billing/page.tsx @@ -12,7 +12,7 @@ import { Button } from '@documenso/ui/primitives/button'; import { LocaleDate } from '~/components/formatter/locale-date'; export default async function BillingSettingsPage() { - const user = await getRequiredServerComponentSession(); + const { user } = await getRequiredServerComponentSession(); const isBillingEnabled = await getServerComponentFlag('app_billing'); diff --git a/apps/web/src/app/(dashboard)/settings/password/page.tsx b/apps/web/src/app/(dashboard)/settings/password/page.tsx index b89e74f3c..90fcbe25d 100644 --- a/apps/web/src/app/(dashboard)/settings/password/page.tsx +++ b/apps/web/src/app/(dashboard)/settings/password/page.tsx @@ -3,7 +3,7 @@ import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get- import { PasswordForm } from '~/components/forms/password'; export default async function PasswordSettingsPage() { - const user = await getRequiredServerComponentSession(); + const { user } = await getRequiredServerComponentSession(); return (
diff --git a/apps/web/src/app/(dashboard)/settings/profile/page.tsx b/apps/web/src/app/(dashboard)/settings/profile/page.tsx index ee0087a9a..716f3c39c 100644 --- a/apps/web/src/app/(dashboard)/settings/profile/page.tsx +++ b/apps/web/src/app/(dashboard)/settings/profile/page.tsx @@ -3,7 +3,7 @@ import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get- import { ProfileForm } from '~/components/forms/profile'; export default async function ProfileSettingsPage() { - const user = await getRequiredServerComponentSession(); + const { user } = await getRequiredServerComponentSession(); return (
diff --git a/apps/web/src/app/(signing)/sign/[token]/complete/page.tsx b/apps/web/src/app/(signing)/sign/[token]/complete/page.tsx index a8081069f..414a6624b 100644 --- a/apps/web/src/app/(signing)/sign/[token]/complete/page.tsx +++ b/apps/web/src/app/(signing)/sign/[token]/complete/page.tsx @@ -53,7 +53,7 @@ export default async function CompletedSigningPage({ recipient.email; return ( -
+
{/* Card with recipient */} diff --git a/apps/web/src/app/(signing)/sign/[token]/complete/share-button.tsx b/apps/web/src/app/(signing)/sign/[token]/complete/share-button.tsx index f4476ade8..caa27cc50 100644 --- a/apps/web/src/app/(signing)/sign/[token]/complete/share-button.tsx +++ b/apps/web/src/app/(signing)/sign/[token]/complete/share-button.tsx @@ -106,7 +106,7 @@ export const ShareButton = ({ token, documentId }: ShareButtonProps) => { - + Share @@ -119,7 +119,7 @@ export const ShareButton = ({ token, documentId }: ShareButtonProps) => { @documenso . Check it out! - + {window.location.origin}/share/{shareLink?.slug || '...'}
diff --git a/apps/web/src/app/(signing)/sign/[token]/form.tsx b/apps/web/src/app/(signing)/sign/[token]/form.tsx index 3a3feb679..36a54879c 100644 --- a/apps/web/src/app/(signing)/sign/[token]/form.tsx +++ b/apps/web/src/app/(signing)/sign/[token]/form.tsx @@ -4,6 +4,7 @@ import { useMemo, useState } from 'react'; import { useRouter } from 'next/navigation'; +import { useSession } from 'next-auth/react'; import { useForm } from 'react-hook-form'; import { completeDocumentWithToken } from '@documenso/lib/server-only/document/complete-document-with-token'; @@ -27,6 +28,7 @@ export type SigningFormProps = { export const SigningForm = ({ document, recipient, fields }: SigningFormProps) => { const router = useRouter(); + const { data: session } = useSession(); const { fullName, signature, setFullName, setSignature } = useRequiredSigningContext(); @@ -60,7 +62,11 @@ export const SigningForm = ({ document, recipient, fields }: SigningFormProps) = return (
diff --git a/apps/web/src/app/(signing)/sign/[token]/layout.tsx b/apps/web/src/app/(signing)/sign/[token]/layout.tsx index 3c56c1718..a25c16c0d 100644 --- a/apps/web/src/app/(signing)/sign/[token]/layout.tsx +++ b/apps/web/src/app/(signing)/sign/[token]/layout.tsx @@ -10,11 +10,11 @@ export type SigningLayoutProps = { }; export default async function SigningLayout({ children }: SigningLayoutProps) { - const user = await getServerComponentSession(); + const { user, session } = await getServerComponentSession(); return ( - -
+ +
{user && }
{children}
diff --git a/apps/web/src/app/(signing)/sign/[token]/page.tsx b/apps/web/src/app/(signing)/sign/[token]/page.tsx index f5f1f3c3d..40a650afd 100644 --- a/apps/web/src/app/(signing)/sign/[token]/page.tsx +++ b/apps/web/src/app/(signing)/sign/[token]/page.tsx @@ -51,7 +51,7 @@ export default async function SigningPage({ params: { token } }: SigningPageProp .then((buffer) => Buffer.from(buffer).toString('base64')) .then((data) => `data:application/pdf;base64,${data}`); - const user = await getServerComponentSession(); + const { user } = await getServerComponentSession(); if ( document.status === DocumentStatus.COMPLETED || @@ -62,7 +62,7 @@ export default async function SigningPage({ params: { token } }: SigningPageProp return ( -
+

{document.title}

diff --git a/apps/web/src/app/not-found.tsx b/apps/web/src/app/not-found.tsx index c8dc15086..f580655af 100644 --- a/apps/web/src/app/not-found.tsx +++ b/apps/web/src/app/not-found.tsx @@ -6,7 +6,7 @@ import { Button } from '@documenso/ui/primitives/button'; import NotFoundPartial from '~/components/partials/not-found'; export default async function NotFound() { - const session = await getServerComponentSession(); + const { session } = await getServerComponentSession(); return ( diff --git a/apps/web/src/components/forms/edit-document/add-fields.action.ts b/apps/web/src/components/forms/edit-document/add-fields.action.ts index d5f2f5fcc..c07758b9f 100644 --- a/apps/web/src/components/forms/edit-document/add-fields.action.ts +++ b/apps/web/src/components/forms/edit-document/add-fields.action.ts @@ -11,10 +11,10 @@ export type AddFieldsActionInput = TAddFieldsFormSchema & { export const addFields = async ({ documentId, fields }: AddFieldsActionInput) => { 'use server'; - const { id: userId } = await getRequiredServerComponentSession(); + const { user } = await getRequiredServerComponentSession(); await setFieldsForDocument({ - userId, + userId: user.id, documentId, fields: fields.map((field) => ({ id: field.nativeId, diff --git a/apps/web/src/components/forms/edit-document/add-signers.action.ts b/apps/web/src/components/forms/edit-document/add-signers.action.ts index 4e6739bd6..05151498a 100644 --- a/apps/web/src/components/forms/edit-document/add-signers.action.ts +++ b/apps/web/src/components/forms/edit-document/add-signers.action.ts @@ -11,10 +11,10 @@ export type AddSignersActionInput = TAddSignersFormSchema & { export const addSigners = async ({ documentId, signers }: AddSignersActionInput) => { 'use server'; - const { id: userId } = await getRequiredServerComponentSession(); + const { user } = await getRequiredServerComponentSession(); await setRecipientsForDocument({ - userId, + userId: user.id, documentId, recipients: signers.map((signer) => ({ id: signer.nativeId, diff --git a/apps/web/src/components/forms/edit-document/add-subject.action.ts b/apps/web/src/components/forms/edit-document/add-subject.action.ts index 14ddef867..8fe37fecc 100644 --- a/apps/web/src/components/forms/edit-document/add-subject.action.ts +++ b/apps/web/src/components/forms/edit-document/add-subject.action.ts @@ -12,7 +12,7 @@ export type CompleteDocumentActionInput = TAddSubjectFormSchema & { export const completeDocument = async ({ documentId, email }: CompleteDocumentActionInput) => { 'use server'; - const { id: userId } = await getRequiredServerComponentSession(); + const { user } = await getRequiredServerComponentSession(); if (email.message || email.subject) { await upsertDocumentMeta({ @@ -23,7 +23,7 @@ export const completeDocument = async ({ documentId, email }: CompleteDocumentAc } return await sendDocument({ - userId, + userId: user.id, documentId, }); }; diff --git a/packages/lib/next-auth/get-server-session.ts b/packages/lib/next-auth/get-server-session.ts index 56df8e7eb..f9196369f 100644 --- a/packages/lib/next-auth/get-server-session.ts +++ b/packages/lib/next-auth/get-server-session.ts @@ -15,7 +15,7 @@ export const getServerSession = async ({ req, res }: GetServerSessionOptions) => const session = await getNextAuthServerSession(req, res, NEXT_AUTH_OPTIONS); if (!session || !session.user?.email) { - return null; + return { user: null, session: null }; } const user = await prisma.user.findFirstOrThrow({ @@ -24,14 +24,14 @@ export const getServerSession = async ({ req, res }: GetServerSessionOptions) => }, }); - return user; + return { user, session }; }; export const getServerComponentSession = async () => { const session = await getNextAuthServerSession(NEXT_AUTH_OPTIONS); if (!session || !session.user?.email) { - return null; + return { user: null, session: null }; } const user = await prisma.user.findFirstOrThrow({ @@ -40,15 +40,15 @@ export const getServerComponentSession = async () => { }, }); - return user; + return { user, session }; }; export const getRequiredServerComponentSession = async () => { - const session = await getServerComponentSession(); + const { user, session } = await getServerComponentSession(); - if (!session) { + if (!user || !session) { throw new Error('No session found'); } - return session; + return { user, session }; }; diff --git a/packages/lib/universal/upload/server-actions.ts b/packages/lib/universal/upload/server-actions.ts index 629d62a2a..5b255fa4f 100644 --- a/packages/lib/universal/upload/server-actions.ts +++ b/packages/lib/universal/upload/server-actions.ts @@ -17,7 +17,7 @@ import { alphaid } from '../id'; export const getPresignPostUrl = async (fileName: string, contentType: string) => { const client = getS3Client(); - const user = await getServerComponentSession(); + const { user } = await getServerComponentSession(); // Get the basename and extension for the file const { name, ext } = path.parse(fileName); diff --git a/packages/trpc/server/context.ts b/packages/trpc/server/context.ts index 252a09317..e1973f08b 100644 --- a/packages/trpc/server/context.ts +++ b/packages/trpc/server/context.ts @@ -3,7 +3,7 @@ import { CreateNextContextOptions } from '@trpc/server/adapters/next'; import { getServerSession } from '@documenso/lib/next-auth/get-server-session'; export const createTrpcContext = async ({ req, res }: CreateNextContextOptions) => { - const session = await getServerSession({ req, res }); + const { session, user } = await getServerSession({ req, res }); if (!session) { return { @@ -12,9 +12,16 @@ export const createTrpcContext = async ({ req, res }: CreateNextContextOptions) }; } + if (!user) { + return { + session: null, + user: null, + }; + } + return { session, - user: session, + user, }; }; diff --git a/packages/ui/primitives/dialog.tsx b/packages/ui/primitives/dialog.tsx index cea2800fc..8a0d8b21e 100644 --- a/packages/ui/primitives/dialog.tsx +++ b/packages/ui/primitives/dialog.tsx @@ -11,9 +11,19 @@ const Dialog = DialogPrimitive.Root; const DialogTrigger = DialogPrimitive.Trigger; -const DialogPortal = ({ className, children, ...props }: DialogPrimitive.DialogPortalProps) => ( +const DialogPortal = ({ + className, + children, + position = 'start', + ...props +}: DialogPrimitive.DialogPortalProps & { position?: 'start' | 'end' }) => ( -
+
{children}
@@ -39,14 +49,14 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; const DialogContent = React.forwardRef< React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, children, ...props }, ref) => ( - + React.ComponentPropsWithoutRef & { position?: 'start' | 'end' } +>(({ className, children, position = 'start', ...props }, ref) => ( +