Dev Blog

BLOG

You can now sign in with a verification code sent to your email

Sign-in used to be Google and GitHub only. Now you can also sign in with a verification code sent to your email address. Why I passed on Apple and X because of the cost, the Clerk settings, how one input field decides between sign-in and sign-up, and why the E2E tests got stuck on bot protection.

Published October 8, 2026

Until now, Metronome.fm only let you sign in with a Google or GitHub account. The sign-in screen is built in-house instead of using the screens provided by Clerk (the service that handles sign-in), so I added the email address field to it myself. Enter your email address, a verification code arrives, and entering that code signs you in. There is no password.

The Metronome.fm sign-in screen. Number 1 is the Google and GitHub buttons. Number 2 is the email address field and the Continue with email button
The sign-in screen
  1. The existing Google and GitHub buttons
  2. The new email address field

This post covers why I passed on signing in with Apple and X, and the Clerk settings. Then it explains how the email address entered in a single field decides between signing in and creating an account. The last two sections are about why the automated tests got stuck on bot protection and the wording I changed along the way.

Passing on Apple and X

With only Google and GitHub, I thought signing in would be hard for iPhone users and for musicians who don't use GitHub. So my first plan was to add Apple.

To use Sign in with Apple on the web, you have to create a Services ID and a key in Apple's developer portal. Using that portal requires an Apple Developer Program membership ($99 a year). Paying an annual fee just for sign-in didn't seem worth it.

I also looked at X. Since February 2026 the X API is pay-per-use only, with no free tier for new developers. Every sign-in has Clerk read one X user record, so each sign-in costs $0.01. The cost comes out of a prepaid balance (credits). Sign-in would stop working whenever the balance ran out, so I passed on X too.

That left verification codes sent by email. They cost nothing extra and work for people who'd rather not use a Google or other account. LINE, which is familiar to many users in Japan, will be added separately.

Clerk settings

In the Clerk dashboard, under User & authentication › Email, I turned on signing in with an email address and verifying it when an account is created. Clerk has separate environments for development and production, so both have the same settings.

Clerk's Sign-in with email settings. Number 1 is the Sign-in with email toggle and number 2 is the Email verification code toggle, both on
Settings for signing in with email
  1. Turn on signing in with an email address
  2. Verify with a code sent by email

Besides a code, Clerk can also verify by having you click a link in the email (Email verification link). A link gets awkward when you open the email on a different device from the one running the app, so I only use codes.

Clerk's Sign-up with email settings. Number 1 is the Require email address toggle, off. Number 2 is the Verify at sign-up toggle with Email verification code checked, on
Settings for creating an account
  1. Don't require an email address
  2. Verify the email address with a code when creating an account

Require email address stays off. For LINE, which I plan to add next, we can't receive the signed-in person's email address unless we apply to LINE for it. If email were required, people whose email address we couldn't receive would be unable to create an account with LINE.

You can also check the settings through the API that Clerk provides for the browser (the Frontend API) at /v1/environment. If email_code is listed as a sign-in method, the dashboard settings have been saved.

{
  "used_for_first_factor": true,
  "first_factors": ["email_code"],
  "verifications": ["email_code"],
  "verify_at_sign_up": true
}

One field for signing in and creating an account

With the Google and GitHub buttons, new users get an account right away. I wanted email to work the same way, so there is a single field, and the app decides between signing in and creating an account after receiving the email address.

First, the app tries to send the code through the sign-in flow. If no account has that email address, Clerk doesn't send a code and returns a form_identifier_not_found error instead. In that case the code is sent through the account creation flow.

const sent = await signIn.emailCode.sendCode({ emailAddress });
if (!sent.error) {
  setEmailCodeFlow("signIn");
  setView({ kind: "emailCode", email: emailAddress });
  return FORM_OK;
}
// このメールアドレスのアカウントがなければ、そのままアカウントを作る
const notFound = parseClerkError(sent.error).some(
  (parsed) => parsed.kind === "identifierNotFound",
);
if (!notFound) return toErrorResult(sent.error, ["emailAddress"]);
const created = await signUp.create({ emailAddress });
if (created.error) return toErrorResult(created.error, ["emailAddress"]);
const signUpSent = await signUp.verifications.sendEmailCode();

To check the code, the app calls signIn.emailCode.verifyCode or signUp.verifications.verifyEmailCode, depending on which flow sent the code. Once the code is verified, finalize completes the sign-in.

The screen for entering the verification code. Number 1 is the text naming the email address the code was sent to. Number 2 is the verification code field
Entering the verification code
  1. The email address the code was sent to
  2. Enter the code you received

If you enter the same email address as an account you created with Google, you sign in to the account you created with Google rather than getting a new one. The email address from Google is attached to the account as already verified.

E2E tests stuck on bot protection

Clerk runs bot protection (Cloudflare Turnstile) when an account is created. The end-to-end (E2E) tests, which drive a browser automatically, avoid it with setupClerkTestingToken from Clerk's @clerk/testing.

Even so, the test that creates an account with a new email address stopped moving forward after entering the address and pressing Continue with email. The test that signs in to an existing account passed.

setupClerkTestingToken intercepts traffic to Clerk's Frontend API with a Playwright route (a feature that catches the browser's requests and lets you replace the response) and rewrites captcha_bypass in the response to true. When this value is true, Clerk in the browser skips Turnstile. It only rewrites the value inside response and client in the response. It doesn't touch meta.client, which comes in error responses.

With a new email address, the first sign-in attempt fails with a 422 (no such account). The meta.client in that error response sets captcha_bypass back to false. As a result, Turnstile runs during the account creation that follows, and in the E2E test browser the check never finished. Reading window.Clerk.client.captchaBypass before and after pressing Continue with email showed it change from true to false.

I fixed it by adding a route in the E2E tests that also rewrites meta.client. The route from setupClerkTestingToken is set on the browser context (the whole browser the test opens). In Playwright, routes set on the page run first, so setting this one on the page after setupClerkTestingToken makes it the one that answers.

await page.route(new RegExp(`^https://${escaped}/v1/`), async (route) => {
  const url = new URL(route.request().url());
  url.searchParams.set("__clerk_testing_token", testingToken);
  const response = await route.fetch({ url: url.toString() });
  const json: unknown = await response.json().catch(() => null);
  if (!isRecord(json)) {
    await route.fulfill({ response });
    return;
  }
  for (const client of [
    json.client,
    isRecord(json.response) ? json.response : undefined,
    isRecord(json.meta) ? json.meta.client : undefined,
  ]) {
    if (isRecord(client) && client.captcha_bypass === false) {
      client.captcha_bypass = true;
    }
  }
  await route.fulfill({ response, json });
});

The tests use test email addresses available in Clerk's development environment (addresses containing +clerk_test) and enter 424242 as the verification code. No email is actually sent.

Dropping sign-in method names from the wording

The note for the free plan in the pricing table said "Google sign-in required", while the landing page and docs said "Google or GitHub". Since more sign-in methods are coming, I rewrote these so they no longer list the names of methods. The pricing table now says "Sign-in required", and the sign-in screen says "Choose how you'd like to sign in". Only places that need an explanation, such as the docs, say "a Google or other account, or your email address".

Share this post

Post on X