mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
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:
@ -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 { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
|
||||||
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-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 { 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 { symmetricDecrypt } from '@documenso/lib/universal/crypto';
|
||||||
import { extractNextHeaderRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
import { extractNextHeaderRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||||
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
||||||
@ -70,8 +71,14 @@ export default async function SigningPage({ params: { token } }: SigningPageProp
|
|||||||
userId: user?.id,
|
userId: user?.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let recipientHasAccount: boolean | null = null;
|
||||||
|
|
||||||
if (!isDocumentAccessValid) {
|
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({
|
await viewedDocument({
|
||||||
|
|||||||
@ -11,9 +11,10 @@ import { useToast } from '@documenso/ui/primitives/use-toast';
|
|||||||
|
|
||||||
export type SigningAuthPageViewProps = {
|
export type SigningAuthPageViewProps = {
|
||||||
email: string;
|
email: string;
|
||||||
|
emailHasAccount?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SigningAuthPageView = ({ email }: SigningAuthPageViewProps) => {
|
export const SigningAuthPageView = ({ email, emailHasAccount }: SigningAuthPageViewProps) => {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const [isSigningOut, setIsSigningOut] = useState(false);
|
const [isSigningOut, setIsSigningOut] = useState(false);
|
||||||
@ -30,7 +31,9 @@ export const SigningAuthPageView = ({ email }: SigningAuthPageViewProps) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await signOut({
|
await signOut({
|
||||||
callbackUrl: `/signin?email=${encodeURIComponent(encryptedEmail)}`,
|
callbackUrl: emailHasAccount
|
||||||
|
? `/signin?email=${encodeURIComponent(encryptedEmail)}`
|
||||||
|
: `/signup?email=${encodeURIComponent(encryptedEmail)}`,
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
toast({
|
toast({
|
||||||
@ -59,7 +62,7 @@ export const SigningAuthPageView = ({ email }: SigningAuthPageViewProps) => {
|
|||||||
onClick={async () => handleChangeAccount(email)}
|
onClick={async () => handleChangeAccount(email)}
|
||||||
loading={isSigningOut}
|
loading={isSigningOut}
|
||||||
>
|
>
|
||||||
Login
|
{emailHasAccount ? 'Login' : 'Sign up'}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user