Skip to Content
suntzu rcdocs
Bits

auth.email-code — Someone signs in by typing the code from the email

  • Trigger: "Sign in with the code" on the "Check your email" screen of /sign-in, after asking for a sign-in email (auth.email-link). For phones: the link opens in whatever browser the mail app picks, the code signs in where the person asked.
  • Who: anyone who received the email.
  • Path: apps/app/src/app/(site)/sign-in/sign-in-form.tsx (CheckEmail) → authClient.signIn.emailOtp → POST /auth/sign-in/email-otp → Better Auth email-otp plugin (apps/api/src/auth/auth.ts) → new session row and cookie → a full page load of the page they came from (/me by default). That page comes from ?next= and is checked by safeNext (apps/app/src/lib/safe-next.ts): a path on this site, or /me.
  • Data: reads and deletes the code's row in verification (identifier sign-in-otp-<email>, a hash of the code and the tries so far, 15 minutes); writes user the first time, and session.
  • Rules: spec 0006. The code is created with the link, in the same email (createVerificationOTP inside sendMagicLink); only the latest email's code works, and it works once. 3 wrong tries spend it. Stored hashed. Never in the subject or the preview. Signing in with it creates the account like the link and syncs the crew role from CREW_EMAILS. It only ever lands on this site: ?next= is parsed as a URL and kept only if it stays on our origin, because browsers read /\evil.com as //evil.com (spec 0010). The plugin's other routes are closed (disabledPaths, 404).
  • Errors: a wrong code says so and lets them retry; an expired or spent code offers "Email me a new one"; Better Auth answers 429 after 3 requests a minute.
  • Test: e2e/auth.email-code.e2e.ts (a new visitor signs in with the code, "123 456" works, a wrong code says so, a used code doesn't work again, a crafted ?next= lands on /me); apps/api/src/auth/sign-in-code.test.ts; apps/app/src/lib/safe-next.test.ts; apps/app/e2e/forms.spec.ts (focus and hints)
  • Observe: API log lines with bit: "auth.sign-in"; locally the email, with its code, is printed by [Mail].
  • Status: verified — 2026-11-18 (end-to-end test)