ExtantApe

payload plugin signup

by ExtantApe
Authentication & SSO
v3
^3.80.0
MIT

Overview

Summary generated from the README

Adds a sign-up flow to Payload with four modes chosen in a settings global. Requests are verified by email, then wait as disabled accounts until staff approve or decline them in the admin. The request form gives the same answer for every address, so it does not reveal which addresses have accounts. Requires Payload 3.80 or later, an access.manage function, and a database with transactions such as MongoDB on a replica set.

Features

  • Open, approval, invite-only and closed modes switched in the admin without a deploy
  • Email verification where the person sets a password on confirm
  • Staff approve or decline requests in the admin, with an onApprove hook and optional automatic approval
  • Custom checks, human verification, held addresses and rate limits per address, email and site
  • Optional staff notices, sign-in help records and resending of unconfirmed links
  • Scheduled pruning of old requests and multi-tenant scoping of the queue

Use cases

  • Run a members-only site where staff vet each new registration before an account can sign in
  • Open registration temporarily and close it again from the admin without redeploying
  • Gate sign-ups with an age check or bot check before any account is created

From the author

Sign-up for Payload: open, approval, invite-only or closed, switched in the admin. Requests are verified by email and wait as disabled accounts for an approve or decline, with no account enumeration.

Installation

npm i @extantape/payload-plugin-signup

0

Stars

0

Forks

1

Open Issues

3 days ago

Last Updated

819

Weekly Downloads

v0.5.0

npm Version

202.7 KB

Unpacked Size

0

Dependencies

GitHub stars

00 since Nov 8

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20260
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
npm weekly downloads

813+813 since Nov 12

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 2026813
Dec 5, 2026954
Dec 4, 2026767
Dec 3, 2026755
Dec 2, 2026717
Dec 1, 2026524
Nov 30, 2026224
Nov 29, 2026202
Nov 28, 202620
Nov 27, 202623
Nov 26, 202618
Nov 25, 202622
Nov 24, 202629
Nov 23, 202645
Nov 22, 2026262
Nov 21, 2026259
Nov 20, 2026254
Nov 19, 2026254
Nov 18, 2026249
Nov 17, 2026238
Nov 16, 2026221
Nov 15, 20260
Nov 14, 2026210
Nov 13, 20260
Nov 12, 20260

Each point is npm's rolling 7-day download count.

Health Score

66/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1453471434-root.svg)](https://payloaddirectory.dev/plugins/1453471434-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1453471434-root"><img src="https://payloaddirectory.dev/badge/1453471434-root.svg" alt="Payload Directory"></a>
Updated Dec 2, 2026Created Nov 11, 2026Published Dec 2, 2026

README

payload-plugin-signup

Sign-up for Payload: open, approval, invite-only or closed, switched in the admin. Requests are verified by email and wait as disabled accounts for an approve or decline. The request form is built not to tell whether an address has an account; its limits are below.

Status: 0.5.0 is the latest release, on npm as @extantape/payload-plugin-signup. It changes existing behavior for every site, so read Changes to existing behavior before upgrading: transactions are required unless a site opts out, onApprove runs before the account is activated, the client address is read from headers only when the site says how, and staff notices are capped. A site on 0.2.0 should also follow Upgrading from 0.2.0. 0.4.0 adds automatic approval in approval mode (autoApprove), a staff notice (notifyStaff) and sign-in help (signInHelp). 310 tests pass against a real MongoDB (in memory, single-node replica set) on Payload 3.92. Some failures in those tests are stand-ins: a read or a write made to fail. An independent security read of 0.1.0 found two problems before release, both fixed and tested (see docs/decisions.md). None of the plugin has run on a real site or been used from a real sign-in form, and no real email has been sent: the tests capture email. 0.5.0 adds afterConfirm, holdAddress, resendSignup (the function and its endpoint), linkHours, the request's locale and site in emails and notices, an existing-account email for waiting accounts, and recentFailureCount. The admin button for resending is built and has 12 jsdom tests, but it has not run in a real Payload admin: see Sending a new link. Integration into a real site is next.

What it does

  • Four modes, chosen in Sign-up settings in the admin and in force at once, with no deploy:
    • Open: anyone who confirms their email gets an account.
    • Approval: a confirmed request waits as a disabled account until staff approve or decline it.
    • Invite only: the form refuses, with your message. Accounts come from your own invitations.
    • Closed: the form refuses, with your message. SIGNUP_MODE (or the forceMode option) locks the mode from configuration. Anything unreadable or unknown counts as closed.
  • A request has an email and your own fields (plain Payload fields, so Payload validates them and the admin shows them). No account and no password yet. Sign-up emails a link. Opening it shows a short form: the person chooses their password and presses "Confirm my email". Opening the link alone changes nothing, because mail scanners open links. Only then is the account made, so only the person with the inbox can set one up under that address. In approval mode it can't sign in until it's approved.
  • The same answer every time: "Thanks. Check your email to continue." That goes for a new address, one that already has an account or is waiting for approval (its owner gets an email saying so), and one that's held (nothing is sent). An email or details that can't be accepted are refused, with the same refusal for every address. Requests for one address at the same moment get the usual answer too. One the database still can't save after ten tries fails. "Waiting for approval" is only shown at sign-in, after the password matched.
    • Limits. The same answer relies on MongoDB with transactions. It isn't promised without transactions or on other databases, and the tests use MongoDB only. It also relies on your code: put refusals in checks, don't let a check look the address up, don't give your fields validators or database rules that depend on what's already stored, and don't let a hook of yours on signup-requests throw. The check of a request's email and details doesn't change or roll back your own transaction. The save can, as the next point says.
    • Inside your own transaction, treat any error submitSignup throws as the whole transaction lost. If the real save fails there, Payload rolls back the transaction, including your earlier work in it. A later commit can appear to succeed with that work gone.
    • Nothing on signup-requests can be unique. The plugin throws at startup if any field there has unique, or any entry in indexes does, including ones another plugin adds. It checks again for each sign-up request that gets past the mode, the human check and the site and address limits, including on a site started without onInit. Don't enforce uniqueness with your own validator or hook either. On MongoDB it also reads the collection's real indexes, at startup and again in that same check. If any index besides _id is unique, or is being made unique (prepareUnique), the site won't start, and a running one answers each request that reaches the check with a 500 and saves nothing. It does the same if it can't read the list, so the database user needs listIndexes, which MongoDB's read and readWrite roles include. A collection that doesn't exist yet is fine. With disableDBConnect and onInit on, startup fails after about 10 seconds (not tested). The check adds one database read to each request that reaches it (about 0.2 ms against a local test database, and about one round trip over a network). On other databases, SQL included, the plugin doesn't read indexes, so keeping them free of unique ones is up to you. A request there can get 503 checkFailed while a unique index is in place, and the index still has to be removed.
  • A set time to answer: a request that reaches the per-email step is answered after a set time (answerAfterMs, 2 seconds by default), counted from after your checks. The email is sent in the background and the answer never waits for it. See Answer time and serverless hosts.
  • After confirming (afterConfirm, optional): your function can name a page on your own site to send the person to. See After confirming.
  • Holding an address (holdAddress, optional): an address you won't take gets the same answer as any other, and nothing is sent or stored. See Holding an address.
  • Resending a link from server code or an endpoint, for a request that was never confirmed. linkHours sets how long a link works. See Sending a new link.
  • Staff decide in the admin. Open a request and set Status to Approved or Declined, or select several and use Edit. A waiting request can only be approved or declined; nothing else on it can be changed. Approving runs your onApprove (roles, memberships) while the account still can't sign in, then activates it and emails "You're in". Declining deletes the account, which never signed in, and sends a polite email with your optional note. If onApprove fails, nothing changes and no email goes out.
  • Automatic approval (autoApprove, optional), in approval mode. Once the person has confirmed, your function is asked about the waiting request and its account. If it answers exactly true, the request is approved through the same save staff make: the account is activated, onApprove runs, "You're in" goes out, and the decision time is kept with Decided by left empty. Any other answer leaves the request waiting for staff, and so does a thrown error, an account that isn't there and waiting, or an approval that doesn't go through. A request that a check flagged is never put to your function. See Automatic approval and the staff notice.
  • A staff notice (notifyStaff, optional) when something is left for staff: a confirmed request that wasn't approved automatically, or a new sign-in help request. A request approved automatically, or in open mode, sends staff nothing.
  • Sign-in help (signInHelp, optional, off by default). Each failed sign-in through Payload's REST login is recorded against the address that was typed, whether or not an account has it. Only a keyed hash of the address, the kind and the time are stored, for 7 days. From that record the plugin answers two questions for your sign-in form: whether a try should pass an extra check of yours first (needsStepUp), and whether to offer help (needsSignInHelp). A help request is kept for managers only when the typed address would be offered help. The plugin locks no accounts. See Sign-in help.
  • Your checks run before anything is stored, for example an age gate. A check can refuse with a message, flag the request for staff ("minor"), or add values to the new account. Answers meant only for checks (answers, such as a birth month and year) are never stored. A check that breaks refuses the request. See Checks.
  • Checks again at confirm (confirmChecks, optional): run when the person confirms, before the account is made, with the stored details and flag but never the check-only answers. A refusal declines the request; a check that breaks refuses for now and the link still works later.
  • Rate limits per network address, per email and site-wide. Past the email limit, nothing happens, with the same answer. Use your own limiter, or the built-in one, which stores only hashed keys. A limiter that breaks refuses, except the site-wide help cap, where the caller still gets the usual thanks and nothing is stored.
    • In a burst right at the limit, the built-in limiter may refuse more than it needs to, possibly all of them. For the email limit that means the usual answer and no email, so the person has to ask again. Don't point its reads at a replica that can lag behind. A limiter of your own has to hold its limit when tries arrive together, for example with one atomic increment. Count every call as one try: the plugin asks only when it means to count.
    • Which address counts: none, by default. A forwarded header can say anything unless your own proxy sets it, so the plugin reads no headers until you pass clientAddress. Without an address, the per-address limits (sign-up, confirm and help requests) are skipped and the site-wide ones still hold. Behind one proxy that sets or overwrites x-real-ip on every request (Vercel does), pass the exported addressFromProxyHeaders, which reads x-real-ip, else the last x-forwarded-for entry. Behind several proxies or a CDN with its own header, pass a function that reads the header your host vouches for.
    • The site-wide limit (200 an hour) is a cheap way for anyone to block sign-up for an hour. On a public site, use verifyHuman (Turnstile or similar) as well.
  • No back door: once a site has users, an account can't be created by a signed-out API call. Accounts come through sign-up, from staff, or from your own code.
  • Transactions required: approving, declining and confirming each write more than one document. The plugin won't start on a database without transactions (MongoDB needs a replica set) unless you set allowWithoutTransactions: true. Without them, the account is activated only after the request is saved as approved, and if activating fails, the account and the request are set back to waiting. A failure part-way can still leave other writes behind, such as an account made at confirm.
  • Logs: when something fails, the plugin logs a fixed message with the error's name and a code. Only names and codes on its own list are repeated; an unlisted name shows as Error with no code, and an unlisted code is left out. It leaves out the error's message, stack and other details. This covers the plugin's own log lines. What Payload, your mail adapter or your own functions log is up to them.
  • Retention: requests decided, abandoned or never confirmed are deleted after 90 days (retentionDays), with any account that was never confirmed. Waiting requests stay until someone decides them. With sign-in help, failure records are deleted after 7 days and help requests after 90 (signInHelp.retentionDays). Run pruneSignupRequests(payload) daily: it does all of this, and nothing is deleted without it.
  • A human check (Turnstile or similar) through verifyHuman. Nothing is wired by default; on a public site, wire one.
  • Who manages it is yours to say, and required. access.manage decides who sees and decides requests and changes the mode, and only an exact true counts: see Access. The plugin won't start without it, so a site can't leave the queue open to every signed-in member. signupStatus is shown only to the account itself and to managers. What checks set for the account (a minor flag, say) is kept out of the queue's view.

On its own, and with others

On its own: it needs a users auth collection, Payload's email, and your access.manage. Checks, roles on approval and a human check are functions you pass in. It doesn't depend on any other plugin.

Needs: Payload ^3.80.0 as a peer dependency. No other EXTANT APE plugin is required.

Works with:

  • Age Gate: its ageGateCheck goes in checks. A too-young person is refused, a minor is flagged in the queue, and minorUntil is written to the new account. The birth month and year stay in answers and are never stored. Its "stay blocked" cookie comes back through setCookies, from Age Gate's next release. Age Gate 0.1.x set it on req.responseHeaders, which Sign-up doesn't pass on (see Checks), so with 0.1.x the cookie is not set.
  • A tenant plugin (such as Payload's multi-tenant plugin): pass scopeField and scopeFor, and add signup-requests to its collections, so each site sees its own queue. A link then works only on the site it was asked on.

Color Theory: none yet. The screens are your own and take your site's CSS. The plain fallback pages the plugin serves use fixed colors and have no hook yet.

Family: It's part of the Identity family (a working draft): plugins designed to sit together for accounts and access. Age Gate is the member it's wired to today.

Install

npm install @extantape/payload-plugin-signup
import { signupPlugin } from '@extantape/payload-plugin-signup'

export default buildConfig({
  plugins: [
    signupPlugin({
      // None of these can be `unique`.
      fields: [
        { name: 'firstName', type: 'text', required: true },
        { name: 'lastName', type: 'text', required: true },
      ],
      toUser: (d) => ({ name: `${d.firstName} ${d.lastName}` }),
      checks: [myAgeGate], // ({ data, answers, email, req, payload }) => { refuse?, flag?, userData?, setCookies? }
      onApprove: async ({ user, req, payload }) => {
        /* give roles */
      },
      access: { manage: ({ req }) => req.user?.role === 'admin' }, // required
      emails: { verify: myBrandedVerifyEmail }, // any of verify, pending, approved, declined, alreadyHasAccount
      urls: { signIn: 'https://example.com/login', resetPassword: 'https://example.com/forgot-password' },
    }),
  ],
})

Build the collections' indexes before first use (signup-requests, signup-attempts, and the new signupStatus on your users; with signInHelp, also sign-in-failures and sign-in-help). If you build your own confirm page, show what was asked for with readSignupRequest, ask for the password there and post { token, password }; never confirm when the page loads. With a tenant plugin, pass scopeField and scopeFor, and add signup-requests to your tenant plugin's collections, so each site sees its own queue. The mode setting is one for the whole install.

Answer time and serverless hosts

submitSignup, and so POST /api/signup/request, answers a request that gets past the mode, the human check, the address and site limits, your checks and the check of its email and details no sooner than answerAfterMs after those steps. It's a whole number of milliseconds from 500 to 10000, and 2000 by default. A request that couldn't be saved fails after the same time. Refusals made earlier (a closed form, a check's refusal, an email or details that can't be accepted, or that check itself failing) are answered straight away.

The request is saved before it's answered. If saving takes longer than answerAfterMs, the answer waits for it, so set a time comfortably longer than your database needs. What your checks and other steps before this point take is added on top.

The email is sent in the background, so an answer can arrive before the email has gone, and a failure to send shows only in your logs.

  • A server that stays running (next start, a container) needs nothing more.
  • A serverless host (Vercel, AWS Lambda and the like) can stop a function once it has answered, and an email still sending would be lost. Give waitUntil, the host's way to keep working after the answer:
import { waitUntil } from '@vercel/functions'
signupPlugin({ waitUntil, access })

// or, with Next.js
import { after } from 'next/server'
signupPlugin({ waitUntil: (work) => after(work), access })

It's called once for each request that reaches this step, whatever the outcome, with a promise that never rejects. Next's after only works while a request is being handled, so if your own scripts call submitSignup outside one, use a function that allows for that. If waitUntil throws, the request is still answered and the log says so. A host with no way to keep working after the answer can't promise the email is sent. Without waitUntil, the log warns whenever an email is still sending at the answer.

Automatic approval and the staff notice

signupPlugin({
  access,
  // Asked once the person has confirmed, in approval mode. Only exactly `true` approves.
  autoApprove: async ({ request, user, req, payload }) => looksFine(request.details),
  // A list of addresses, or your own function.
  notifyStaff: ['[email protected]'],
})
OptionWhat it takesDefault
autoApprove({ request, user, req, payload }) => boolean. request is the waiting request, without the link's hash or what checks set for the account. user is its account.None: every request waits for staff
notifyStaffA list of email addresses, or (notice) => void with { about, reason, request or help, url, req, payload }None: nobody is told
emails.staffNoticeThe email sent to a notifyStaff listA short email with the reason and a link to the request in the admin. It leaves out the person's name, address and details
  • Your function is asked only in approval mode, and only about a request no check flagged. A flag from checks or confirmChecks always sends the request to staff.
  • Keep it to reading. It runs after the confirm is saved, so the request is already waiting if anything in it fails.
  • The approval is an ordinary save of the request with Status set to Approved, made with no user. Your own hooks on signup-requests see it as they see a staff approval.
  • POST /api/signup/verify and verifySignup answer active for a request approved this way, and the person gets "You're in" without the "request is in" email.
  • If onApprove throws, or staff decide the request in the same moment, the automatic approval changes nothing and the request is left as it was. onApprove runs before the account is activated, so a refusal leaves it unable to sign in.
  • Your function doesn't see userData. What checks set for the account isn't on the request it gets, so a check that marks a minor only through userData doesn't stop an automatic approval. Have that check also return a flag (a flagged request never reaches your function), or look at the account inside your function: user already carries what checks set.
  • Inside your own transaction, automatic approval isn't tried. The request waits for staff.
  • A notice has a reason: waiting (automatic approval wasn't tried), flagged, notApproved (your function didn't answer true) or failed. A notice that can't be sent is logged and changes nothing.
  • Staff notices are capped for the whole site at 30 an hour (limits.staffNotice). Past it, the notice is skipped and logged, and the request or help request is still in the admin.

After confirming

signupPlugin({ access, afterConfirm: ({ user, status }) => (status === 'active' ? '/welcome' : '/thanks') })
  • afterConfirm({ user, status, req, payload }) runs after the account is made, once the confirm has committed. status is 'active' or 'pending'. user is the account without its password, hash, salt or tokens.
  • It answers a path on your own site, or null or undefined for none. The path must start with one /, be at most 2048 characters, have no backslash, space or control character, and stay on the same site once parsed. Anything else is dropped, and the log says that the answer was dropped, without the value or the address.
  • A function that throws is logged by the error's name only. The confirm still succeeds.
  • With a valid path, POST /api/signup/verify from the plugin's page answers 303 See Other to it, with Cache-Control: no-store, Referrer-Policy: no-referrer and any cookies your confirm checks set. As JSON the answer gains next: { status, next }. Without a valid path, nothing changes from 0.4.0.

Holding an address

signupPlugin({ access, holdAddress: async (email, { scope, req, payload }) => await myBlockList.has(email) })
  • Only an exact false lets an address through. true, any other value and a thrown error all hold it, and the log says so without the address.
  • A held address gets the same answer, in the same time, as every other: nothing is stored and no email is sent. It is checked before any account lookup, so nothing shows whether the address has an account.
  • It is checked again when someone opens a link. A held address's link answers like an expired one (badLink), and the request is deleted when they confirm. Opening the confirm page or reading the details (GET /api/signup/details) gives the same badLink and shows nothing, and deletes nothing.
  • A timing limit. Confirming a held link takes a few milliseconds longer than confirming an unknown one (the host's holdAddress runs, and the request is deleted). The confirm answer has no set time like the sign-up form's answerAfterMs. Someone with a real link already knows the address, and the link goes only to its inbox, so this tells nobody anything new. A site that wants the two to look alike can wrap holdAddress to take a fixed time.
  • It runs on every request and every resend, so keep it quick and keep it to a lookup.
import { resendSignup } from '@extantape/payload-plugin-signup'
const { ok, message } = await resendSignup(payload, requestID, req)
  • Only a request that was never confirmed gets a new link. Any other status throws notUnverified (409). The earlier link stops working, and linkHours starts again.
  • It refuses as the form does (closed or invite-only, the site-wide limit) and counts against the same per-email limit, so a resend can't add to an address's three emails an hour. The held check and the address checks run as for a new request.
  • The answer is for staff and says what happened: "A new link is on its way.", "Not sent: this address is held.", "Not sent: this request was declined.", "Not sent: this address already has an account (they were told).", or "Not sent: too many sign-up emails for this address in the last hour. Try again later." Don't pass it on to a visitor.
  • POST /api/signup/resend with { id } as JSON (Content-Type: application/json, else 415, so a form posted from another site is refused) is for managers only (access.manage answering exactly true, else 403 forbidden). It reads the request as that manager, so a request they can't read answers 404 notFound, the same as one that doesn't exist. It answers 202.
  • Admin button. The request's edit page has a Resend the confirmation link to button in the sidebar, for staff only. It shows only for unconfirmed requests (others get a short note), and shows the answer above in a status region and an error in an alert. It is exported as ResendLinkButton from @extantape/payload-plugin-signup/client and needs react 19 or later and the admin's own @payloadcms/ui. After installing or upgrading, run payload generate:importmap, or the admin can't find it. It has been tested in jsdom, with Payload's hooks mocked, and not in a real admin or browser. Staff can also call the endpoint, or the function from your own code.
  • linkHours (1 to 168, default 48) replaces verifyHours, which still works and gives the same value. Giving both with different values stops startup.

Sign-in help

signupPlugin({ access, signInHelp: true })

// In your own sign-in form's server code:
import { needsStepUp, needsSignInHelp, recordSignInFailure, requestSignInHelp } from '@extantape/payload-plugin-signup'

if ((await needsStepUp(payload, email)) !== 'no') await myBotCheck(req) // 'unknown' counts as 'yes'
// ...after a wrong email or password through the Local API:
const { help } = await recordSignInFailure(payload, email)
OptionWhat it doesDefault
signInHelptrue, or the settings below. Adds two collections, one endpoint and a hook on your users' REST loginOff
signInHelp.stepUpAfterFailures for one typed address before needsStepUp answers yes3
signInHelp.stepUpWindowMinutesHow far back those failures count60
signInHelp.helpAfterRunsRuns of failures in 7 days before help is offered. A run is stepUpAfter more failures2
signInHelp.retentionDaysDays a help request is kept if nobody ticks Handled90
signInHelp.sitesRequired with scopeField. ({ req }) => 'all' or a list of site ids: the sites whose help requests this manager seesNone
limits.help, limits.helpEmail, limits.helpSiteHelp requests an hour per network address (only with clientAddress), per typed address, and for the whole site. Past the first two, a request gets 429 busy. The site-wide cap counts only requests that would be stored and never changes the answer: past it, a request is answered as usual and not stored5, 3 and 20
slugs.signInFailures, slugs.signInHelpThe two collections' slugssign-in-failures, sign-in-help
FunctionAnswer
needsStepUp(payload, email)'yes', 'no' or 'unknown'. It only reads. 'unknown' means the record couldn't be read, so treat it as 'yes'
needsSignInHelp(payload, email)true or false. It only reads. false when the record can't be read
recordSignInFailure(payload, email){ help }, after recording one failure. It throws if the record can't be written
requestSignInHelp(payload, { email, message? }, req){ ok: true, message }, or a SignupError: email, busy or unavailable
recentFailureCount(payload, email, sinceMs)The number of failures recorded for the typed address since sinceMs (a time in milliseconds, at most 7 days back), or null if the record can't be read. A plain Error if sign-in help is off or sinceMs isn't a time that has passed. Server code only: no endpoint calls it, it takes no rate limit, and an address with an account and one without answer alike
  • What is recorded. A failed sign-in is a wrong password or an address nobody has. Payload answers both with the same error, and both are recorded against the typed address in the same way, so the record can't show which addresses have accounts. The stored row has a keyed hash of the address (HMAC with your Payload secret), the kind and the time. A sign-in that worked isn't recorded, and neither is a waiting account with the right password or an unverified one. With Payload's lock on, a try at a locked account is recorded as a failure, so an address with an account collects failures the same way as one without.
  • Where it is recorded. The plugin records failures from Payload's REST login (POST /api/users/login) by itself. Payload runs no hook when a Local API sign-in fails, so a form that calls payload.login records the failure with recordSignInFailure. GraphQL sign-ins aren't recorded.
  • The step-up check is yours. The plugin only answers whether one is needed. It doesn't run a bot check and doesn't refuse a sign-in.
  • Locks. The plugin locks nothing. Payload has its own lock (auth.maxLoginAttempts, 5 by default), and its sign-in answer for a locked account differs from the one for an address nobody has. That is Payload's answer, outside this plugin; sign-in help answers the same either way. Set it to 0 on your users collection if you want no locks.
  • Help requests. POST /api/signup/sign-in-help and requestSignInHelp take the typed address and an optional message of up to 1000 characters. The request is stored only when that address would be offered help. For any other address the answer is the same and nothing is stored. No account is looked up at any point.
    • What a caller sees. The status, the words and the headers are the same whether or not a request was stored, and so is every later answer. So is the time to the answer, as long as the checks and the save finish inside answerAfterMs; if they take longer, the answer waits for them. The per-network and per-email limits count every request, whatever address was typed, and past them the answer is 429 busy. A failure record that can't be read gives 503 unavailable for every address alike.
    • The site-wide cap (limits.helpSite) stores at most that many requests an hour, for the whole site. It is asked only about a request that would be stored. Past it, the request isn't stored, the log has a warning, and the caller gets the usual thanks, so a person who needed help won't hear back and isn't told to try again. Size it for your busiest hour and watch the log for that warning. In a burst right at the cap, the built-in limiter may store fewer than it could. A limiter that breaks or answers anything but true stores nothing, the same way. A request that would be stored but can't be saved is logged and answered as usual too.
    • Your own rateLimit is asked about helpSite only for a request it would store, with the usual three arguments, so counting every call is right. It still has to hold its limit when requests arrive together.
    • Serverless hosts. The staff notice goes out after the answer, so on a serverless host give waitUntil (see Answer time and serverless hosts).
  • Who handles them. Managers read help requests in the admin under Sign-in help, and nobody creates one over the API. The typed address, the message and the site can't be edited. Ticking Handled and saving deletes the request.
  • Several sites. With scopeField, a help request keeps the site from scopeFor in a text field named site, and a request with no site is refused. signInHelp.sites says which sites a manager sees. Only 'all' or a list of ids counts, and the plugin builds the query itself. The plugin won't start with scopeField and no signInHelp.sites. Leave sign-in-help out of your tenant plugin's collections.

Upgrading from 0.2.0

The plugin's stored data and collections don't change. If one of your sign-up fields is unique, step 9 changes your own. 0.3.0 doesn't arrive through a ^0.2.0 range, so change the version yourself.

  1. On a serverless host, set waitUntil (above).
  2. Expect each sign-up request to take at least 2 seconds. Show a busy state on your form, and check that any timeout around it is longer. Tests that call submitSignup can set answerAfterMs: 500.
  3. Don't expect the email to have been sent when submitSignup returns.
  4. If you pass rateLimit, check that it holds its limit when tries arrive at once.
  5. If you search or alert on the logs, err now holds only name and, when there is one, code. Both come from a fixed list: your own error classes show as Error. To see why an email failed, use your mail provider's logs.
  6. Handle the details error code. POST /api/signup/request answers 400 with it when details can't be accepted. submitSignup throws a SignupError with it in place of Payload's ValidationError; when a field check failed, the list is still at error.data.errors. An email Payload won't accept gets the email code.
  7. Send complete, valid details with every request, repeats included. Each request is checked as a new one.
  8. Field hooks and validators on email and your fields now run once more for each request, in the check before saving, so keep them free of side effects. No collection hooks run in that check. With transactions, it also makes a test write that is always rolled back. Inside your own transaction, that happens only on MongoDB.
  9. Make nothing on signup-requests unique, or the site won't start. Remove unique from your fields, and from any field or index that your config or another plugin adds to that collection. Then drop the index from the database, because removing the setting may leave it there. On MongoDB, list them in mongosh with db.getCollection('signup-requests').getIndexes(), and drop each one marked unique or prepareUnique, except _id_, with db.getCollection('signup-requests').dropIndex('<name>'). The site won't start until they're gone. On an SQL database, use a migration. The plugin doesn't check there. If a value has to be unique on accounts, handle that where you make or edit the account.

Upgrading from 0.4.0

  1. Rename verifyHours to linkHours, and keep it within 1 to 168. The old name still works for now.
  2. Expect an existing-account email for a person whose request is waiting for approval. It says the request is waiting and has no sign-in link. Sites with their own alreadyHasAccount email get account.status ('active' or 'pending') and should handle both.
  3. Every email and staff notice now carries locale (the language the person asked in, or null) and scope (the site, or null). Later emails use the values stored on the request, not those of whoever confirms or decides. onApprove also gets scope.
  4. The requests collection has a new locale field. On MongoDB nothing needs doing. On SQL, run your migration.
  5. Run payload generate:importmap. The requests collection has a new admin button for resending a link, and the admin can't find it until the import map includes it.

Checks

A check is a function in checks, run in order when a request comes in:

type Check = (args: { data; answers; email; req: PayloadRequest; payload }) =>
  { refuse?: string; flag?: string; userData?: Record<string, unknown>; setCookies?: string[] } | void
  • req is the request itself, headers and cookies included. A check written to take less (Partial<PayloadRequest>) still fits. Calling submitSignup from your own code with a partial request, or none, is fine: Payload's createLocalReq completes it, with empty headers.
  • setCookies are whole Set-Cookie values. POST /api/signup/request sets them on its response, whether the request is taken or refused. submitSignup hands them back as setCookies on its result, or on the SignupError it throws, so your own form can set them. Each must be printable ASCII (space to ~), as cookie syntax allows; anything else counts as a broken check and refuses (503 checkFailed) before anything is stored or emailed.
  • Confirm checks (confirmChecks) work the same way: they get the request itself, and their setCookies go on the POST /api/signup/verify response, as JSON or the page, confirmed or refused. verifySignup hands them back on its result or its SignupError.
  • Nothing else about the response is a check's to change. Each check runs with an empty req.responseHeaders of its own, and Sign-up throws that list away afterwards, so headers a check adds there never reach the response. The request's own list (an auth strategy's, say) is put back untouched. Sign-up and its checks don't import each other: the check returns plain values.

Endpoints

Method and pathBodyAnswer
GET /api/signup/mode{ mode, accepting, message }
POST /api/signup/request{ email, details, answers?, humanToken? }202 { ok, message }, or an error { error: { code, message } }, either with any cookies the checks set
GET /api/signup/verify?token=A small page: what was asked for (email and details), then choose a password and confirm
GET /api/signup/details?token={ email, details: [{ name, label, value }] } for your own confirm page: only the email and the confirmShows fields, no ids, and it never uses up the link. A used, expired or made-up token all get the same 400 badLink. Counts against the verify rate limit
POST /api/signup/verify{ token, password } as JSON, or the page's form (token, password, confirm)JSON { status: 'pending' or 'active', next? }, or a page (a 303 to next when afterConfirm gave one)
POST /api/signup/resend{ id } as JSON, managers only202 { ok, message } saying what happened, or an error
POST /api/signup/sign-in-help (with signInHelp){ email, message? }202 { ok, message } whether or not the request was stored, or an error

Error codes: notUnverified, forbidden, notFound, closed, inviteOnly, email, details (details that can't be accepted; the message names the fields when it can), password, passwordMismatch (the page only), refused, checkFailed, human, busy, badLink, hasAccount (an account was made for the address since they asked), unavailable (a help request that couldn't be taken). The same functions are exported for your own pages: submitSignup, verifySignup, currentMode, and readSignupRequest to show what was asked for on your confirm page (it only reads; the link still works). The confirm page shows only the email and the fields you list in confirmShows (default none), because a mistyped address sends the link to a stranger. Hidden fields and fields with their own read access never show.

Access

access.manage decides who manages sign-up, and only an answer of exactly true, for a signed-in user, counts. Anything else is a no: false, 1, 'yes', an object, a query (Where), or an error thrown or rejected. An error doesn't escape as a 500: REST answers 403, as for anyone else who isn't a manager. It's typed as Payload's Access so existing rules fit, but what it returns is never passed to Payload, so an object that looks like a query can't widen the queue to every request.

WhereA managerAnyone else, or signed out
Sign-up requests (applicants' emails and details)Reads, decides, deletesNothing
Sign-up settings (the mode and messages)Reads and changesNothing
An account's signupStatusReadsOnly the account itself reads its own
Sign-in help requests (typed addresses and messages)Reads, ticks Handled, deletes. With scopeField, only for the sites signInHelp.sites givesNothing
The record of failed sign-insNothingNothing

Nobody creates requests or help requests, or changes signupStatus, directly: the plugin does. Each site seeing only its own queue comes from a tenant plugin with scopeField (above), not from a query in access.manage.

Commands

npm test          # integration tests, in-memory MongoDB
npm run typecheck
npm run build

License

MIT. See LICENSE.

Similar plugins