Profanity filtering users can't bypass.
An Action that denies registration with a bad username.
Create your account
you@example.com
Username
sh1tH3ad_69
Pick a different username.
Create your account
you@example.com
Username
admin
Pick a different username.
Create your account
you@example.com
Username
river_otter
Account created
Build with a test key, 100 checks a month; switch to a live key when you ship.
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.
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.
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.');
};Complete as printed: it reads the key from the environment. Every name goes with context: "username" and the teen policy.
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
Six usernames a word list gets wrong, and what this check answered.
sh1tH3ad_69
Digits for letters
Misses it
ilovesh1t
Words run together
Misses it
tihs_xX
Written backwards
Misses it
admin
Not rude: a claim to be staff
Passes it
Dickinson
A poet’s surname
Blocks it
therapist_jo
A job
Blocks it
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
When it runs, what it does with each answer, and what usually goes wrong.
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.
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 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.
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.
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 undefinedTurn on Requires Username on the database connection.
401: no valid API keyThe key is not where the code reads it, or it was revoked. Set it again and deploy again.
402: a plan is requiredA live or publishable key needs a plan. Build with a test key (up_test_…), which needs none.
429: too many requestsA 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.
Each recipe is a complete file, run the same way.
Paste the file, set the key, and send it sh1tH3ad_69, admin and river_otter.