Unprofane

Auth0 username check in one Action

An Action that denies registration with a bad username.

Live in four steps

Build with a test key, 100 checks a month; switch to a live key when you ship.

  1. Before you start

    • An Auth0 tenant with a database connection.

      For a username, turn on Requires Username on the connection; without one the code checks the nickname.

    • Pre User Registration runs for database and passwordless sign-ups, not for social ones.

  2. Store the key

    • In the Action’s editor, open Secrets and add UNPROFANE_API_KEY with your key.

      The code reads it as event.secrets.UNPROFANE_API_KEY.

  3. Where the file goes

    • In the Auth0 dashboard, create a custom Action on the Pre User Registration trigger, paste the code, deploy it, and add it to the trigger.

      It uses the runtime’s own fetch, so it needs no packages.

    // Auth0 Pre User Registration Action. Add UNPROFANE_API_KEY under the Action's Secrets.
    exports.onExecutePreUserRegistration = async (event, api) => {
      const username = event.user.username ?? event.user.nickname;
      if (!username) return;
      let result;
      try {
        const res = await fetch('https://api.unprofane.com/v1/check', {
          method: 'POST',
          headers: { Authorization: `Bearer ${event.secrets.UNPROFANE_API_KEY}`, 'Content-Type': 'application/json' },
          body: JSON.stringify({ text: username, context: 'username', policy: 'teen' }),
          signal: AbortSignal.timeout(3000),
        });
        if (!res.ok) throw new Error(`Unprofane answered ${res.status}`);
        result = await res.json();
      } catch {
        // No answer is not a yes: refuse for now, in words the sign-up form shows.
        return api.access.deny('username_unchecked', 'The username could not be checked. Try again in a minute.');
      }
      if (!result.allowed) api.access.deny('username_refused', 'Pick a different username.');
    };
    1. Line 9The key comes from the Action’s Secrets, never the code.
    2. Line 10Read as a handle: glued words are split, leetspeak and look-alike letters are read, and the name is tried backwards too. The teen policy lets mild words through and turns the rest away; pick the one for your audience.
    3. Line 11A sign-up waits on this, so it gives up after three seconds.
    4. Line 17No answer is not a yes: the sign-up is refused, never let through unchecked.

    Complete as printed: it reads the key from the environment. Every name goes with context: "username" and the teen policy.

  4. Check that it works

    • Sign up through Universal Login as sh1tH3ad_69: the form shows Pick a different username. and no user appears under User Management.

    • admin is refused the same way; river_otter signs up.

    • The Action’s Test tab runs it with an event you edit: set user.username there.

    What the run sends, and what comes backNode 24

    1. sh1tH3ad_69api.access.deny("username_refused", "Pick a different username.")
    2. adminapi.access.deny("username_refused", "Pick a different username.")
    3. river_otterno deny
    4. Unprofane unreachableapi.access.deny("username_unchecked", "The username could not be checked. Try again in a minute.")

It reads the name, not a list

Six usernames a word list gets wrong, and what this check answered.

  1. sh1tH3ad_69

    Digits for letters

    Misses it

    blockreads shitheadleetspeak
  2. ilovesh1t

    Words run together

    Misses it

    blockreads shitleetspeakconcatenation
  3. tihs_xX

    Written backwards

    Misses it

    blockreads shitreversed
  4. admin

    Not rude: a claim to be staff

    Passes it

    blockreserved
  5. Dickinson

    A poet’s surname

    Blocks it

    allow
  6. therapist_jo

    A job

    Blocks it

    allow
Out of 6

4 let through2 innocent blocked

4 turned away2 innocent let through

76.5%

Unprofane

Balanced mode, as the recipes run it

32.5%

Perspective API

Set to flag as much clean text as Unprofane

Toxic usernames caught. Held-back judged test set, run of .How it was measured

How it behaves in production

When it runs, what it does with each answer, and what usually goes wrong.

When the check runs
  1. Typed
  2. Unprofane checks
  3. Saved
  4. Shown to others

Before the user exists. A refused sign-up is never created, and the person reads the message in the sign-up form. It runs at registration only: a username changed later through the Management API is not checked.

Allow, review and block
allow
Goes through
review
Turned away, like a block
block
Turned away

allowed is true only when action is allow. The recipes turn away review as well as block: a username has no moderator queue, and asking for another name costs the person a few seconds. To accept a name held for review and look at it later, test action !== "block" instead and keep the user id where a person will read it. A name that claims to be the platform or its staff, such as admin, comes back with matches[0].category set to reserved, and the code says so in its own words.

Every field of the answer is in the API reference.

When Unprofane does not answer

When Unprofane does not answer within the timeout, or answers with an error status, the Action refuses the sign-up with The username could not be checked. Try again in a minute. It never lets an unchecked name through. To let sign-ups through while Unprofane is unreachable, return in the catch instead of calling api.access.deny.

How this recipe is run on every change

Run with the runtime’s own fetch, given an event and an api object in place of Auth0’s: the three names below, and once with Unprofane unreachable. Auth0 itself is not involved.

Every sign-up is refused as unchecked

Read the Action’s logs. An error status from Unprofane, such as no plan or a wrong key, lands in the catch. Build with a test key.

event.user.username is undefined

Turn on Requires Username on the database connection.

401: no valid API key

The key is not where the code reads it, or it was revoked. Set it again and deploy again.

402: a plan is required

A live or publishable key needs a plan. Build with a test key (up_test_…), which needs none.

429: too many requests

A test key’s free checks are capped across the account, a month’s with no plan and a day’s on one, and every plan has a per-minute limit. The answer’s type says which.

Every error, and what to send instead, is on the errors page.

The same check, elsewhere

Each recipe is a complete file, run the same way.

Run this recipe with your API key

Paste the file, set the key, and send it sh1tH3ad_69, admin and river_otter.

Get your API key