Skip to content

Auth & backend

Flag fake signups in Appwrite with a users.*.create Function

Run an Appwrite Function on the users.*.create event to verify each new user's email, then label or block undeliverable and disposable accounts with node-appwrite.

Updated 2026-11-26

This recipe runs an Appwrite Function every time a user is created. The function verifies the new user's email, adds labels such as emaildisposable or emailundeliverable, saves the verdict in the user's preferences, and blocks accounts whose address cannot receive mail or belongs to a disposable inbox service. There is no native Qelka integration for Appwrite: you deploy one Node.js function.

Appwrite also ships Email policies: Deny free emails, Deny aliased emails and Deny disposable emails, which refuse those addresses at sign-up (check that your Appwrite version has them). If disposable inboxes are your only concern, turn that policy on first. The function adds what a switch does not: domains that cannot receive mail and typo suggestions, a verdict stored on every user, and your own choice between blocking and flagging.

What you need

  • An Appwrite project (Cloud or self-hosted) and, to deploy from your machine, the Appwrite CLI.
  • A Qelka API key. It sits in Appwrite's variable store, so create a restricted key limited to email. A sk_test_ key returns simulated results and never spends credits: see Test mode.

Steps

1. Create the function

Create a Node.js function from the Console, or with the CLI in your project folder:

bash
appwrite init functions

Then, in the folder the CLI created for the function, run npm install node-appwrite. Pick a Node.js runtime of 18 or later, which has fetch and AbortSignal.timeout built in. The code below uses the object parameters of current node-appwrite versions.

2. Configure events, scopes and the secret

In the Console, open the function's Settings:

  • Events: add users.*.create. The * stands for any user ID, so every new account triggers the function. Do not subscribe to users.*.update: the function updates users itself.
  • Scopes: grant users.read and users.write. They apply to the short-lived key the function receives in the x-appwrite-key header.
  • Environment variables: create QELKA_API_KEY with your key as the value, and mark it as Secret.

Event triggers need no execute permission, so leave Execute access empty: nobody can then call the function over HTTP and spend your credits. Appwrite's default timeout of 15 seconds, which you can change under Settings, is plenty for one fast check.

3. The code

Save as src/main.js:

javascript
import { Client, Users } from 'node-appwrite'

async function verifyEmail(email, log) {
  try {
    const response = await fetch('https://api.qelka.com/v1/email', {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ email, mode: 'fast' }),
      signal: AbortSignal.timeout(8000),
    })
    if (response.ok) return await response.json()
    const failure = await response.json().catch(() => null)
    log(`email check skipped: ${failure?.error?.type ?? response.status} request ${response.headers.get('X-Request-Id')}`)
  } catch (cause) {
    log(`email check skipped: ${cause.name}`)
  }
  return null
}

export default async ({ req, res, log, error }) => {
  const user = req.bodyJson
  if (!user?.$id || !user.email) return res.json({ skipped: true })

  const client = new Client()
    .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
    .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
    .setKey(req.headers['x-appwrite-key'] ?? '')
  const users = new Users(client)

  const result = await verifyEmail(user.email, log)
  const status = result ? result.status : 'unchecked'
  const disposable = result?.checks.disposable === true
  const block = status === 'undeliverable' || disposable

  const labels = new Set(user.labels ?? [])
  if (!result) labels.add('emailunchecked')
  if (status === 'undeliverable') labels.add('emailundeliverable')
  if (disposable) labels.add('emaildisposable')

  try {
    await users.updateLabels({ userId: user.$id, labels: [...labels] })
    await users.updatePrefs({
      userId: user.$id,
      prefs: { ...user.prefs, emailStatus: status, emailSuggestion: result?.did_you_mean ?? null },
    })
    if (block) await users.updateStatus({ userId: user.$id, status: false })
  } catch (cause) {
    error(`could not update user ${user.$id}: ${cause.message}`)
  }

  return res.json({ status, blocked: block })
}

The event body is the new User object, read with req.bodyJson. updateLabels and updatePrefs replace the whole list or object, which is why the code merges with the values already on the user. Labels may only contain alphanumeric characters, up to 36 each, hence names without dashes.

mode: 'fast' runs the syntax, DNS and list checks and skips the mailbox check, which waits on the recipient's mail server. It still catches typos, dead domains and disposable inboxes. See the email reference.

4. Deploy

bash
appwrite push functions

If you set or changed the variable after the last deployment, deploy again: Appwrite applies variable changes on the next deployment.

5. Test it

With a test key, create users in the Console's Auth section or from your app:

  • disposable@example.com gets the label emaildisposable and is blocked;
  • nomx@example.com is undeliverable (domain_no_mx), labelled emailundeliverable and blocked;
  • jane@example.com stays active with emailStatus: unknown, since fast mode skips the mailbox check.

Each run appears in the function's executions in the Console, with the log lines.

6. What each answer does

Result Meaning Function
undeliverable Bad syntax, or a domain that does not exist or takes no mail Labels and blocks, stores did_you_mean
risky, reason disposable A disposable inbox service Labels and blocks
risky, other reasons A catch-all domain or a full mailbox Keeps the user, emailStatus: risky
unknown In fast mode, smtp_not_checked: nothing wrong was found Keeps the user
No answer API unreachable, key or balance problem Keeps the user, label emailunchecked, logged

Never block on unknown. updateStatus with status: false blocks the account; Appwrite's Users API suggests it as an alternative to deleting, since the ID stays reserved. Your client may have opened a session right after sign-up, so check how your app handles a session that was opened before the block. To flag rather than block, remove the updateStatus call and filter users by label in your back office. Block disposable email signups helps you choose.

Add an IP signal

The User object carries no IP address. If you also want to flag signups from Tor, VPNs or high-risk networks, subscribe a second function to users.*.sessions.*.create: the Session object it receives has the ip the session was opened from and the userId. Call https://api.qelka.com/v1/ip once per user (skip users that already carry a label such as ipchecked), and add a signupreview label when risk.level is high or flags.tor is true. Treat it as a reason for an extra step, not a refusal. Its key then needs the ip restriction too. See the IP reference.

Handle errors and rate limits

Nothing is billed on errors. The function never retries: a 429, a 5xx or a timeout ends as emailunchecked, and the user keeps full access. 401, 402 and 403 mean a wrong key, an empty balance or a restricted key: they show in the execution logs with the error type and the request id. Re-check emailunchecked users later from a scheduled function. A key allows 200 requests per 10 seconds, and each email check costs 1 credit. To check users created before the function existed, export them and run a bulk file check. See Errors and Rate limits.

Frequently asked questions

Can an Appwrite Function stop the account from being created?
Not as far as we know: the users.*.create event fires once the account exists, and the function runs after it. It can label, block or delete the user within seconds. For a refusal at sign-up itself, turn on Appwrite's Deny disposable emails policy, and use the function for what that switch does not cover.
Should I store the verdict in labels or in preferences?
Use labels for anything you act on. They can only be changed through the Users API with a server key, since the Account API has no method for them, and permissions can refer to them. Preferences can be rewritten by the signed-in user through the Account API, so keep only informational copies there.
Where does the API key go?
In the function's environment variables, marked as Secret, in the Console under the function's Settings. Appwrite applies variable changes on the next deployment, so redeploy after setting it, and do not start your own names with APPWRITE_: Appwrite's built-in variables use that prefix and take precedence. The Appwrite key itself needs no storage: the function receives a short-lived one in the x-appwrite-key header.

More in Auth & backend

All integrations

Put this check in your product

Get an API key in under a minute. 100 free credits every month, no card required.

  • 100 free credits a month
  • No card
  • Test keys spend nothing
  • Cancel any time