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({

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>