fix: show correct authentication action for account required

When using account required auth for a given document
this change now shows the sign up or sign in button
depending on if an account actually exists within
Documenso.

This change should reduce friction and confusion when a
recipient has been invited to a document.
This commit is contained in:
Mythie
2024-06-20 10:59:07 +10:00
parent fbf4bd605f
commit cc667233c6
2 changed files with 14 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import { getCompletedFieldsForToken } from '@documenso/lib/server-only/field/get
import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
import { getRecipientSignatures } from '@documenso/lib/server-only/recipient/get-recipient-signatures';
import { getUserByEmail } from '@documenso/lib/server-only/user/get-user-by-email';
import { symmetricDecrypt } from '@documenso/lib/universal/crypto';
import { extractNextHeaderRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
@ -70,8 +71,14 @@ export default async function SigningPage({ params: { token } }: SigningPageProp
userId: user?.id,
});
let recipientHasAccount: boolean | null = null;
if (!isDocumentAccessValid) {
return <SigningAuthPageView email={recipient.email} />;
recipientHasAccount = await getUserByEmail({ email: recipient?.email })
.then((user) => !!user)
.catch(() => false);
return <SigningAuthPageView email={recipient.email} emailHasAccount={!!recipientHasAccount} />;
}
await viewedDocument({