fix: show correct authentication action for account required (#1191)

## Description

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.

## Related Issue

<!--- If this pull request is related to a specific issue, reference it
here using #issue_number. -->
<!--- For example, "Fixes #123" or "Addresses #456". -->

## Changes Made

- Updated the ssr for the signing page to fetch whether a user account
exists when document auth is required
- Pass the user exists flag to the document auth required page

## Testing Performed

- Created and sent a document to a user with an account and one without an account in both a logged in and logged out state and confirmed that the dialogs are displayed as expected.
This commit is contained in:
Lucas Smith
2024-06-26 12:03:01 +10:00
committed by GitHub
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({

View File

@@ -11,9 +11,10 @@ import { useToast } from '@documenso/ui/primitives/use-toast';
export type SigningAuthPageViewProps = {
email: string;
emailHasAccount?: boolean;
};
export const SigningAuthPageView = ({ email }: SigningAuthPageViewProps) => {
export const SigningAuthPageView = ({ email, emailHasAccount }: SigningAuthPageViewProps) => {
const { toast } = useToast();
const [isSigningOut, setIsSigningOut] = useState(false);
@@ -30,7 +31,9 @@ export const SigningAuthPageView = ({ email }: SigningAuthPageViewProps) => {
});
await signOut({
callbackUrl: `/signin?email=${encodeURIComponent(encryptedEmail)}`,
callbackUrl: emailHasAccount
? `/signin?email=${encodeURIComponent(encryptedEmail)}`
: `/signup?email=${encodeURIComponent(encryptedEmail)}`,
});
} catch {
toast({
@@ -59,7 +62,7 @@ export const SigningAuthPageView = ({ email }: SigningAuthPageViewProps) => {
onClick={async () => handleChangeAccount(email)}
loading={isSigningOut}
>
Login
{emailHasAccount ? 'Login' : 'Sign up'}
</Button>
</div>
</div>