Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Tell a new sender when email is not set up, instead of to check their inbox
Claude7d11a02ce45a
diff --git a/src/app/(auth)/signup/page.tsx b/src/app/(auth)/signup/page.tsxindex cd480a6..6ac338c 100644--- a/src/app/(auth)/signup/page.tsx+++ b/src/app/(auth)/signup/page.tsx@@ -2,6 +2,7 @@ import { SignupShell } from "@/components/auth/signup-shell";import { redirectIfSignedIn } from "@/lib/auth/server";import { readPasswordSignInPolicy, readSsoConfig } from "@/lib/auth/sso";import { buildBranding } from "@/lib/branding";+import { canSendEmail } from "@/lib/services/email";import { getSettings } from "@/lib/settings";import { describeSignupPolicy } from "@/lib/signup-policy";@@ -13,6 +14,7 @@ export default async function SignupPage() {return (<SignupShell+ emailConnected={canSendEmail()}passwordSignIn={readPasswordSignInPolicy().enabled}sso={sso ? { name: sso.name } : null}signupAvailable={buildBranding(settings).signupAvailable}diff --git a/src/components/auth/signup-shell.tsx b/src/components/auth/signup-shell.tsxindex b8f23bc..4fa42e3 100644--- a/src/components/auth/signup-shell.tsx+++ b/src/components/auth/signup-shell.tsx@@ -19,6 +19,10 @@ import {import { signUpSchema } from "@/lib/schemas/auth";const defaultSuccessMessage = "Check your email to verify your sender account.";+// With no email provider connected, the verification email cannot be sent.+// Logging in sends it again, so that works once email is set up.+const SIGNUP_EMAIL_NOT_CONNECTED_MESSAGE =+ "Your account is created, but this site can't send email yet, so the email that verifies your address couldn't be sent. Ask an administrator to finish email setup in Settings, Organization. Once it's set up, log in and the verification email will be sent.";type AuthErrorLike = {code?: string;@@ -34,6 +38,8 @@ const SIGNUP_RULE_ERROR_CODES = new Set([]);type SignupShellProps = {+ /** False when the install has no email provider to send with. */+ emailConnected?: boolean;/** False when password sign-in is turned off, so accounts come from SSO. */passwordSignIn?: boolean;/** Single sign-on, when the install has it (lib/auth/sso.ts). */@@ -242,6 +248,7 @@ function SignupFormCard({}export function SignupShell({+ emailConnected = true,passwordSignIn = true,signupAvailable = true,signupRule = null,@@ -253,6 +260,7 @@ export function SignupShell({return (<LiveSignupShell+ emailConnected={emailConnected}passwordSignIn={passwordSignIn || !sso}signupRule={signupRule}sso={sso}@@ -284,10 +292,12 @@ function SignupClosedCard() {}function LiveSignupShell({+ emailConnected,passwordSignIn,signupRule,sso,}: {+ emailConnected: boolean;passwordSignIn: boolean;signupRule: string | null;sso: SsoOption | null;@@ -440,7 +450,13 @@ function LiveSignupShell({}setSuccessEmail(validationResult.data.email);- setSuccessMessage(defaultSuccessMessage);+ // With no email provider the confirmation email cannot have gone, so+ // the sender is not told to wait for it (issue #95).+ setSuccessMessage(+ emailConnected+ ? defaultSuccessMessage+ : SIGNUP_EMAIL_NOT_CONNECTED_MESSAGE,+ );setShowSuccess(true);setIsSubmitting(false);}@@ -455,7 +471,9 @@ function LiveSignupShell({onEmailChange={handleChange("email")}onFullNameChange={handleChange("fullName")}onPasswordChange={handleChange("password")}- onResendVerification={handleResendVerification}+ onResendVerification={+ emailConnected ? handleResendVerification : undefined+ }onSsoError={setBannerMessage}onSubmit={handleSubmit}passwordSignIn={passwordSignIn}diff --git a/src/lib/services/email.test.ts b/src/lib/services/email.test.tsindex 39cfcc1..c6ef8a7 100644--- a/src/lib/services/email.test.ts+++ b/src/lib/services/email.test.ts@@ -4,6 +4,7 @@ import { test } from "node:test";import type { Resend } from "resend";import {+ canSendEmail,createEmailService,createLazyEmailService,type EmailService,@@ -161,3 +162,24 @@ test("a lazy email service with no provider fails the send, not its creation (isawait assert.rejects(service.send(MESSAGE), /RESEND_API_KEY/);});++test("signup knows when there is no email provider to send with (issue #95)", () => {+ assert.equal(canSendEmail({ NODE_ENV: "production" }), false);+ assert.equal(+ canSendEmail({ NODE_ENV: "production", RESEND_API_KEY: "re_test" }),+ true,+ );+ assert.equal(+ canSendEmail({ EMAIL_DRIVER: "capture", NODE_ENV: "development" }),+ true,+ );+ // The capture driver drops mail, so a real site cannot count on it.+ assert.equal(+ canSendEmail({+ APP_URL: "https://sign.example.com",+ EMAIL_DRIVER: "capture",+ NODE_ENV: "production",+ }),+ false,+ );+});diff --git a/src/lib/services/email.ts b/src/lib/services/email.tsindex 3e84932..4ab79e3 100644--- a/src/lib/services/email.ts+++ b/src/lib/services/email.ts@@ -314,6 +314,22 @@ export function isEmailNotConnectedError(error: unknown): boolean {);}+/**+ * Whether this install has an email provider to send with. Without one,+ * a flow that would tell someone to check their inbox says that email is+ * not set up instead (issue #95).+ */+export function canSendEmail(env: EnvSource = process.env): boolean {+ try {+ createEmailService({ env });+ return true;+ } catch {+ // No provider key, or a driver this deployment cannot use: either way+ // nothing would be sent.+ return false;+ }+}+/*** An email service that is only built when a message is first sent. A flow* that sends email as a side effect after saving its own work (a signer