Integrations · Sign-up and auth
Stop bad emails at WorkOS sign-up
Keep sign-ups with bad email addresses out of an app that uses WorkOS AuthKit. A small endpoint you host runs as WorkOS's user registration action: before WorkOS creates the user, it checks the email address with the API and answers WorkOS with a signed deny when the result is a status you chose to stop (by default invalid and disposable). If the API is slow or down, the endpoint answers allow within about 3 seconds, so the sign-up goes on as long as WorkOS waits that long for your endpoint (WorkOS does not publish its limit).
It is TypeScript with no dependencies, under the MIT licence. Download email-validation-workos.zip: it holds email-validation-workos.ts (the endpoint), worker.ts (the same endpoint as a Cloudflare Worker) and LICENSE.
What gets checked
WorkOS runs a user registration action when someone registers through AuthKit with email and password, Magic Auth, single sign-on (SSO) or a social login such as Google or Microsoft, before the user is created. A registration without an email address goes through unchecked. WorkOS's documentation does not say that the action runs for users you create through its API, users from Directory Sync or accepted invitations, so do not rely on it there.
WorkOS webhooks such as user.created arrive after the user exists and cannot stop a sign-up, so this guide uses the action.
Set it up
This is code you host with your app or as a Cloudflare Worker you deploy from a terminal: there is no browser-only option yet.
Create an API key on the API keys page with the permission Validate addresses and a daily credit cap.
Host the endpoint on a public HTTPS URL. In a Next.js app, put
email-validation-workos.tsinlib/and addapp/api/workos/user-registration/route.ts:import { createWorkosRegistrationAction, optionsFromEnv } from '@/lib/email-validation-workos'; export const POST = createWorkosRegistrationAction(optionsFromEnv(process.env));On Cloudflare Workers, deploy
worker.ts(withemail-validation-workos.tsnext to it) as the Worker's main module. With Express, read the body as text and register the route before anyapp.use(express.json()): a body that was already parsed cannot be verified. Node 22.18 or later imports the.tsfile as it is; with an older Node or a build step, compile it with your app.import express from 'express'; import { createWorkosRegistrationAction, optionsFromEnv } from './email-validation-workos.ts'; const action = createWorkosRegistrationAction(optionsFromEnv(process.env)); const app = express(); app.post('/workos/user-registration', express.text({ type: '*/*', limit: '1mb' }), async (req, res) => { const reply = await action.handleRaw(req.body, req.headers); res.status(reply.status).set(reply.headers).send(reply.body); });Set
EV_API_KEYto your API key on the server. Never put it in browser code.In the WorkOS Dashboard, open Actions, choose the user registration action and set your endpoint's URL. Copy the secret WorkOS generates into
WORKOS_ACTIONS_SECRETon the server and redeploy.Choose the endpoint's error handling behavior, set Enable action and choose Save changes.
Send a test action from the Test tab, then register with
no_mailbox@sandbox.email-validation.org, a test address: it is denied with "This email address cannot receive email…", for free. Do not register with a test address that is allowed, such asaccepted@sandbox.email-validation.org: WorkOS may then send a verification or Magic Auth mail to a domain that receives none.
Settings
| Variable | Value |
|---|---|
WORKOS_ACTIONS_SECRET | Required. The action endpoint's secret from the WorkOS Dashboard. |
EV_API_KEY | Required. Your API key with Validate addresses. |
EV_REGION | eu to check addresses in the EU (EU data residency). |
EV_STOP_STATUSES | The statuses that stop a sign-up, separated by commas: invalid, disposable, catch_all, unknown. Default invalid,disposable. none stops nothing. |
EV_DENY_MESSAGE | The message sent with a deny, up to 500 characters, instead of the default ones. |
While you rotate the actions secret, give both, the old one first, separated by a vertical bar (old|new); the answer is signed with the one that verified WorkOS's request.
A result marked disposable is stopped while disposable is on the list, whatever its status (the API keeps invalid or unknown as the status of some addresses on disposable domains), except an unknown that means our check ran out of time or failed (timeout, internal_error). Otherwise a valid result goes through, and an unknown result is stopped only if you add it to the list, never for timeout or internal_error. A deny for an invalid address adds "Did you mean …?" when the API suggests a correction.
When something fails
- The API is slow (over 3 seconds), down, rate limited or out of credits, or your key is missing or wrong: the endpoint answers allow within about 3 seconds, and the sign-up goes on unchecked. A check is never retried.
- A request that does not carry WorkOS's signature, or whose timestamp is more than 3 minutes off, gets HTTP 401 and is never checked.
- If WorkOS cannot get a valid answer from the endpoint at all (the endpoint is down, its URL is wrong, the secret is missing or wrong, or your host answers slower than WorkOS waits, a cold start included), WorkOS applies the error handling behavior you chose, and WorkOS's default denies the sign-up. Set the secret before you enable the action, and send a test action after each change.
What it costs
Each check costs at most 1 credit, like any validation request. unknown results, errors, malformed addresses and test addresses are free. A check our API finishes after the endpoint stopped waiting can still be charged. Credits come in one-time packs, from $0.15 per 1,000 with the 50,000,000-credit pack (smaller packs cost more per credit), and new accounts get 500 free credits (100 when you sign up with a free email provider such as Gmail, Outlook or Yahoo, another personal mailbox such as a paid one like Fastmail or one from your internet provider, or an address from a relay or alias service). Give the key a daily credit cap.
Privacy
The endpoint sends only the new user's address, in the body of a POST to https://api.email-validation.org (or https://api-eu.email-validation.org), and nothing else WorkOS sent (not the name, the IP address or the user agent). It never puts the address in a URL and sends it to no other host. It logs one line for each denied or unchecked sign-up, with the status and request id, never the address, the key or the secret.