Skip to main content

Overview

useSendVerificationEmail returns a function that sends a verification email to the currently authenticated user. The token expires after 5 minutes. Calling it on an already-verified user is a no-op (resolves without sending).

Usage Example

Parameters

The returned function requires a props object. mode defaults to "code"; in code mode tokenFormat is required and decides what else applies:
"code" | "link"
How the token is delivered. Defaults to "code".
  • "code" — user receives a token to type into your app
  • "link" — user receives a clickable button that verifies automatically
"hex" | "numeric" | "alpha" | "alphanumeric"
Character set for the token.
  • Required in code mode — there’s no default, since "hex" (see below) produces something no one would want to type.
  • Optional when mode: "link" (defaults to "hex") — the token is embedded in a URL, never read by a human, so the format doesn’t matter.
number
Length of the generated token (4–12).
  • Optional in code mode with a "numeric", "alpha" or "alphanumeric" token (defaults to 6).
  • Not allowed when tokenFormat is "hex" — hex ignores length and always produces a fixed 64-character token, so specifying one would be silently meaningless.
  • Optional when mode: "link" (defaults to 6).
string | null
URL to redirect to after link verification; null for none. Only valid with mode: "link" (TypeScript refuses it in code mode). On success it receives verified=true in its query string; an invalid or expired link shows Sublay’s hosted error page instead.Must be an https address on one of your project’s Verified Domains (Dashboard → Settings → Domains). Each entry covers exactly the host it names, never its subdomains: example.com allows https://example.com/… on any port, but not www.example.com, which needs its own entry. A full address such as https://app.example.com covers only that host and port. localhost and *.localhost are always allowed, over http too. Anything else, including a custom-scheme deep link such as myapp://verified, is refused with 400 auth/redirect-url-not-allowed and no email is sent.
These requirements are enforced by TypeScript, not just documented — sendVerificationEmail({ tokenFormat: "numeric" }) compiles, but sendVerificationEmail({ mode: "code" }) (missing tokenFormat) or sendVerificationEmail({ mode: "code", tokenFormat: "hex", tokenLength: 6 }) will fail to type-check.

Returns

The hook returns an async function that resolves with nothing (Promise<void>) when the request completes without a server error.

See Also