Skip to content

Open source CapCut alternative.

TypeScript

feat(site): remove email address verification

David Lee6ca552d3353
diff --git a/site/src/app/cut/app/(home)/settings/profile/page.tsx b/site/src/app/cut/app/(home)/settings/profile/page.tsx
index f2ef0e32..edf160c5 100644
--- a/site/src/app/cut/app/(home)/settings/profile/page.tsx
+++ b/site/src/app/cut/app/(home)/settings/profile/page.tsx
@@ -17,7 +17,6 @@ import { UserAvatar } from "@/cut/components/UserAvatar";
import {
useAccountProfile,
useUpdateDisplayName,
- useVerifyEmail,
visibleName,
} from "@/queries/accountProfile";
@@ -27,7 +26,6 @@ import {
export default function CutProfilePage() {
const { data: profile, isPending, isError } = useAccountProfile();
const update = useUpdateDisplayName();
- const verifyEmail = useVerifyEmail();
// Null means "not edited yet", so the field follows the saved value until
// the user types and again once a save lands.
const [draft, setDraft] = useState<string | null>(null);
@@ -98,29 +96,8 @@ export default function CutProfilePage() {
{visibleName(profile, profile.name)}
</div>
<div className="truncate text-sm text-muted-foreground">{profile.email}</div>
- {profile.emailVerified ? (
+ {profile.emailVerified && (
<p className="mt-1 text-xs text-muted-foreground">Email verified</p>
- ) : (
- <div className="mt-2">
- <Button
- variant="outline"
- size="sm"
- disabled={verifyEmail.isPending}
- onClick={() => verifyEmail.mutate(profile.email)}
- >
- {verifyEmail.isPending ? "Sending…" : verifyEmail.isSuccess ? "Resend email" : "Verify email"}
- </Button>
- {verifyEmail.isSuccess && (
- <p role="status" className="mt-2 text-sm text-muted-foreground">
- Check your inbox for a verification link.
- </p>
- )}
- {verifyEmail.isError && (
- <p role="alert" className="mt-2 text-sm text-red-600">
- Couldn&apos;t send the verification email. Try again.
- </p>
- )}
- </div>
)}
</div>
</div>
diff --git a/site/src/lib/auth.ts b/site/src/lib/auth.ts
index 5e611949..28325715 100644
--- a/site/src/lib/auth.ts
+++ b/site/src/lib/auth.ts
@@ -7,7 +7,6 @@ import { AUTH_COOKIE_DOMAIN, DONKEYCUT_CANONICAL, SU_ORIGIN } from "@/cut/lib/ho
import { provisionSignupGrants } from "@/lib/onboarding/signup-grants";
import { prisma } from "@/lib/prisma";
import { emailPasswordDisabledPaths, emailPasswordGuard, emailPasswordOptions } from "@/lib/email-password-auth";
-import { sendVerificationEmail } from "@/lib/email/send-verification";
import { AUTH_ERROR_PATH } from "@/lib/signInReturn";
// donkeycut.com owns sign-in: the auth pages, the auth API, and the Google
@@ -82,12 +81,6 @@ export const auth = betterAuth({
},
},
emailAndPassword: emailPasswordOptions,
- emailVerification: {
- sendVerificationEmail,
- sendOnSignUp: false,
- sendOnSignIn: false,
- autoSignInAfterVerification: false,
- },
disabledPaths: emailPasswordDisabledPaths,
// A provider callback that fails comes back to sign-in, which says so and
// offers the button again; left unset, production sends it to the landing
diff --git a/site/src/lib/email-password-auth.test.ts b/site/src/lib/email-password-auth.test.ts
index 0c936e75..6f9f36c6 100644
--- a/site/src/lib/email-password-auth.test.ts
+++ b/site/src/lib/email-password-auth.test.ts
@@ -6,24 +6,16 @@ import { emailPasswordDisabledPaths, emailPasswordGuard, emailPasswordOptions }
const password = "test-only-account-password-12345";
const db: Record<string, Record<string, unknown>[]> = {};
-let verificationUrl: string | null = null;
const auth = betterAuth({
baseURL: "http://localhost:3000",
secret: "test-only-auth-secret-with-at-least-32-characters",
database: memoryAdapter(db),
emailAndPassword: emailPasswordOptions,
- emailVerification: {
- sendVerificationEmail: async ({ url }) => { verificationUrl = url; },
- sendOnSignUp: false,
- sendOnSignIn: false,
- autoSignInAfterVerification: false,
- },
disabledPaths: emailPasswordDisabledPaths,
hooks: { before: emailPasswordGuard },
});
beforeEach(async () => {
- verificationUrl = null;
db.user = ["first", "second", "google-only"].map((id) => ({
id, email: `${id}@example.com`, name: id, emailVerified: false,
createdAt: new Date(), updatedAt: new Date(),
@@ -36,33 +28,18 @@ beforeEach(async () => {
db.session = [];
});
-test("verification requires the signed-in account and changes its status only after the email link is opened", async () => {
+test("email verification is closed, even to a signed-in account", async () => {
const signIn = await request("/sign-in/email", { email: "[email protected]", password });
const cookie = signIn.headers.get("set-cookie")!.split(";")[0];
- const send = (body: Record<string, unknown>, cookieValue = cookie) => auth.handler(new Request("http://localhost:3000/api/auth/send-verification-email", {
- method: "POST", headers: { "Content-Type": "application/json", Origin: "http://localhost:3000", Cookie: cookieValue },
- body: JSON.stringify(body),
+ const send = await auth.handler(new Request("http://localhost:3000/api/auth/send-verification-email", {
+ method: "POST", headers: { "Content-Type": "application/json", Origin: "http://localhost:3000", Cookie: cookie },
+ body: JSON.stringify({ email: "[email protected]" }),
}));
- expect((await send({ email: "[email protected]" }, "")).status).toBe(401);
- expect((await send({ email: "[email protected]" })).status).toBe(401);
- expect((await send({ email: "[email protected]", callbackURL: "https://attacker.example" })).status).toBe(403);
- expect(verificationUrl).toBeNull();
- const callbackURL = "/app/settings/profile";
- expect((await send({ email: "[email protected]", callbackURL })).status).toBe(200);
- expect(db.user.find((user) => user.id === "first")!.emailVerified).toBe(false);
- expect(verificationUrl).not.toBeNull();
- const link = new URL(verificationUrl!);
- expect(link.searchParams.get("callbackURL")).toBe(callbackURL);
- const invalid = new URL(link);
- invalid.searchParams.set("token", "invalid");
- await auth.handler(new Request(invalid));
+ const verify = await auth.handler(new Request("http://localhost:3000/api/auth/verify-email?token=any"));
+
+ expect(send.status).toBe(404);
+ expect(verify.status).toBe(404);
expect(db.user.find((user) => user.id === "first")!.emailVerified).toBe(false);
- const verified = await auth.handler(new Request(link));
- expect(verified.status).toBe(302);
- expect(verified.headers.get("location")).toBe(callbackURL);
- expect(db.user.find((user) => user.id === "first")!.emailVerified).toBe(true);
- expect(db.user.find((user) => user.id === "second")!.emailVerified).toBe(false);
- expect(verified.headers.get("set-cookie")).toBeNull();
});
function request(path: string, body: Record<string, unknown>) {
diff --git a/site/src/lib/email-password-auth.ts b/site/src/lib/email-password-auth.ts
index 5f46b7bc..a72d2c49 100644
--- a/site/src/lib/email-password-auth.ts
+++ b/site/src/lib/email-password-auth.ts
@@ -1,24 +1,21 @@
-import { APIError, createAuthMiddleware, getSessionFromCtx } from "better-auth/api";
+import { APIError, createAuthMiddleware } from "better-auth/api";
export const emailPasswordOptions = {
enabled: true,
};
-// Password recovery needs an email delivery flow before it can be exposed.
+// The site sends no email, so neither password recovery nor address
+// verification is offered.
export const emailPasswordDisabledPaths = [
"/set-password",
"/request-password-reset",
"/reset-password",
+ "/send-verification-email",
+ "/verify-email",
];
export const emailPasswordGuard = createAuthMiddleware(async (ctx) => {
- if (ctx.path === "/send-verification-email") {
- const session = await getSessionFromCtx(ctx);
- if (!session || typeof ctx.body?.email !== "string" || ctx.body.email.toLowerCase() !== session.user.email.toLowerCase()) {
- throw new APIError("UNAUTHORIZED", { message: "Sign in to verify your email." });
- }
- }
- if (ctx.path !== "/sign-in/email" && ctx.path !== "/sign-up/email" && ctx.path !== "/send-verification-email") return;
+ if (ctx.path !== "/sign-in/email" && ctx.path !== "/sign-up/email") return;
const callback: unknown = ctx.body?.callbackURL;
if (callback !== undefined && (
typeof callback !== "string" ||
diff --git a/site/src/lib/email/send-verification.ts b/site/src/lib/email/send-verification.ts
deleted file mode 100644
index e3d405a4..00000000
--- a/site/src/lib/email/send-verification.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { APIError } from "better-auth/api";
-import { emailFrom, getResend } from "@/lib/email/resend";
-import { withEmailBudget } from "@/lib/email/send-budget";
-
-/** Verification links expire; deliver within the transactional budget immediately. */
-export async function sendVerificationEmail({
- user,
- url,
-}: {
- user: { email: string };
- url: string;
-}) {
- const from = emailFrom();
- if (!from)
- throw new Error("RESEND_FROM_EMAIL is required for verification emails.");
- const result = await withEmailBudget("transactional", () =>
- getResend().emails.send({
- from,
- to: user.email,
- subject: "Verify your Donkey Cut email",
- text: `Confirm your email address for your Donkey Cut account:\n\n${url}\n\nIf you did not request this email, you can ignore it.`,
- }),
- );
- if (!result || result.error) {
- throw new APIError("SERVICE_UNAVAILABLE", {
- message: "Could not send the verification email. Please try again.",
- });
- }
-}
diff --git a/site/src/queries/accountProfile.ts b/site/src/queries/accountProfile.ts
index 94f658db..f799b93a 100644
--- a/site/src/queries/accountProfile.ts
+++ b/site/src/queries/accountProfile.ts
@@ -74,12 +74,3 @@ export function useUpdateDisplayName() {
});
}
-export function useVerifyEmail() {
- return useMutation({
- mutationFn: (email: string) =>
- apiFetch<{ status: boolean }>("/api/auth/send-verification-email", {
- method: "POST",
- body: JSON.stringify({ email, callbackURL: "/app/settings/profile" }),
- }),
- });
-}