fix: pdf viewer and embeds

This commit is contained in:
David Nguyen
2025-02-20 15:06:36 +11:00
parent 250381fec8
commit 50a41d0799
20 changed files with 572 additions and 665 deletions

View File

@ -7,8 +7,7 @@
"build": "next build",
"start": "next start -p 3002",
"lint:fix": "next lint --fix",
"clean": "rimraf .next && rimraf node_modules",
"copy:pdfjs": "node ../../scripts/copy-pdfjs.cjs"
"clean": "rimraf .next && rimraf node_modules"
},
"dependencies": {
"@documenso/assets": "*",

View File

@ -7,8 +7,7 @@
"build": "next build",
"start": "next start",
"lint:fix": "next lint --fix",
"clean": "rimraf .next && rimraf node_modules",
"copy:pdfjs": "node ../../scripts/copy-pdfjs.cjs"
"clean": "rimraf .next && rimraf node_modules"
},
"dependencies": {
"@documenso/prisma": "*",

View File

@ -8,11 +8,17 @@ import { BrandingLogo } from '~/components/general/branding-logo';
export type EmbedAuthenticationRequiredProps = {
email?: string;
returnTo: string;
isGoogleSSOEnabled?: boolean;
isOIDCSSOEnabled?: boolean;
oidcProviderLabel?: string;
};
export const EmbedAuthenticationRequired = ({
email,
returnTo,
isGoogleSSOEnabled,
isOIDCSSOEnabled,
oidcProviderLabel,
}: EmbedAuthenticationRequiredProps) => {
return (
<div className="flex min-h-[100dvh] w-full items-center justify-center">
@ -28,7 +34,14 @@ export const EmbedAuthenticationRequired = ({
</AlertDescription>
</Alert>
<SignInForm className="mt-4" initialEmail={email} returnTo={returnTo} />
<SignInForm
isGoogleSSOEnabled={isGoogleSSOEnabled}
isOIDCSSOEnabled={isOIDCSSOEnabled}
oidcProviderLabel={oidcProviderLabel}
className="mt-4"
initialEmail={email}
returnTo={returnTo}
/>
</div>
</div>
);

View File

@ -26,7 +26,7 @@ export const loader = async ({ request }: Route.LoaderArgs) => {
const session = await getOptionalSession(request);
if (!session.isAuthenticated) {
return redirect('/signin');
throw redirect('/signin');
}
const [limits, banner] = await Promise.all([

View File

@ -1,5 +1,11 @@
import { Outlet, isRouteErrorResponse, useRouteError } from 'react-router';
import {
IS_GOOGLE_SSO_ENABLED,
IS_OIDC_SSO_ENABLED,
OIDC_PROVIDER_LABEL,
} from '@documenso/lib/constants/auth';
import { EmbedAuthenticationRequired } from '~/components/embed/embed-authentication-required';
import { EmbedDocumentWaitingForTurn } from '~/components/embed/embed-document-waiting-for-turn';
import { EmbedPaywall } from '~/components/embed/embed-paywall';
@ -20,17 +26,38 @@ export function headers({ loaderHeaders }: Route.HeadersArgs) {
};
}
export function loader() {
// SSR env variables.
const isGoogleSSOEnabled = IS_GOOGLE_SSO_ENABLED;
const isOIDCSSOEnabled = IS_OIDC_SSO_ENABLED;
const oidcProviderLabel = OIDC_PROVIDER_LABEL;
return {
isGoogleSSOEnabled,
isOIDCSSOEnabled,
oidcProviderLabel,
};
}
export default function Layout() {
return <Outlet />;
}
export function ErrorBoundary() {
export function ErrorBoundary({ loaderData }: Route.ErrorBoundaryProps) {
const { isGoogleSSOEnabled, isOIDCSSOEnabled, oidcProviderLabel } = loaderData || {};
const error = useRouteError();
if (isRouteErrorResponse(error)) {
if (error.status === 401 && error.data.type === 'embed-authentication-required') {
return (
<EmbedAuthenticationRequired email={error.data.email} returnTo={error.data.returnTo} />
<EmbedAuthenticationRequired
isGoogleSSOEnabled={isGoogleSSOEnabled}
isOIDCSSOEnabled={isOIDCSSOEnabled}
oidcProviderLabel={oidcProviderLabel}
email={error.data.email}
returnTo={error.data.returnTo}
/>
);
}

View File

@ -1,7 +1,7 @@
import { data } from 'react-router';
import { match } from 'ts-pattern';
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
import { isUserEnterprise } from '@documenso/ee/server-only/util/is-document-enterprise';
import { isDocumentPlatform } from '@documenso/ee/server-only/util/is-document-platform';
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
@ -49,7 +49,7 @@ export async function loader({ params, request }: Route.LoaderArgs) {
);
}
const { user } = await getSession(request);
const { user } = await getOptionalSession(request);
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
documentAuth: template.authOptions,

View File

@ -2,7 +2,7 @@ import { DocumentStatus, RecipientRole } from '@prisma/client';
import { data } from 'react-router';
import { match } from 'ts-pattern';
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
import { isUserEnterprise } from '@documenso/ee/server-only/util/is-document-enterprise';
import { isDocumentPlatform } from '@documenso/ee/server-only/util/is-document-platform';
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
@ -29,7 +29,7 @@ export async function loader({ params, request }: Route.LoaderArgs) {
const token = params.url;
const { user } = await getSession(request);
const { user } = await getOptionalSession(request);
const [document, fields, recipient] = await Promise.all([
getDocumentAndSenderByToken({

View File

@ -10,7 +10,6 @@
"start": "npm run with:env -- cross-env NODE_ENV=production node build/server/main.js",
"clean": "rimraf .react-router && rimraf node_modules",
"typecheck": "react-router typegen && tsc",
"copy:pdfjs": "node ../../scripts/copy-pdfjs.cjs",
"with:env": "dotenv -e ../../.env -e ../../.env.local --"
},
"dependencies": {
@ -100,4 +99,4 @@
"vite-plugin-babel-macros": "^1.0.6",
"vite-tsconfig-paths": "^5.1.4"
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -24,12 +24,6 @@ server.use(
// Cache with revalidation for rest of static files.
c.header('Cache-Control', 'public, max-age=0, stale-while-revalidate=86400');
}
// Custom cache for static file pdf.worker.min.js
if (path === './build/client/pdf.worker.min.js') {
c.header('Cache-Control', 'public, max-age=3600, stale-while-revalidate=86400');
c.header('ETag', 'pdf.worker.min.js');
}
},
}),
);