Last updated:
After this page, a dev or staging worker has the accounts your tests and demos sign in with, and re-running the command changes only what drifted. It uses the admin-token-gated auth plane every Lunora worker mounts at /_lunora/admin/auth/*, so it works against a deployed worker with no code of your own.
lunora seed is a different tool. It fills schema tables with generated fake rows, and a generated password column is not a credential a user can sign in with.
Prerequisites
- A worker with
authAdminwired tocreateAuthAdmin(auth)from@lunora/auth(see Authentication). - The root
LUNORA_ADMIN_TOKENof the target worker. Every write here is root-only, so a named admin token is refused with a 403. emailAndPassword.enabledon the auth instance, when the accounts carry passwords.
Write the accounts file
The file lists users and, optionally, organizations. Passwords never go in it: a user names the environment variable that holds its password in passwordEnv.
{
"users": [
{ "email": "ada@example.com", "name": "Ada", "role": "admin", "passwordEnv": "ADA_PASSWORD" },
{ "email": "bob@example.com", "name": "Bob", "emailVerified": false }
],
"organizations": [{ "slug": "acme", "name": "Acme", "owner": "ada@example.com", "members": [{ "email": "bob@example.com", "role": "member" }] }]
}| Field | Meaning |
|---|---|
users[].email, name | Required. The email is the lookup key, matched in lowercase. |
users[].role | Optional. Written after the create, because app user.create.before hooks often reset a role they do not allow. |
users[].emailVerified | Optional, default true. |
users[].data | Optional. App-defined user.additionalFields; a column the auth plane owns (role, ban state, …) is ignored. |
users[].passwordEnv | Optional. Name of the environment variable holding the password. |
organizations[].slug | Required, in the form the plane stores: lowercase letters, digits and single hyphens. Another form is refused. |
organizations[].owner | Required. Email of a user in the same file. The owner always holds the role owner. |
organizations[].members | Optional. { email, role } for each other member, who must also be in users. |
Run it
The following command ensures the accounts on the local dev worker, with one shared password for every user that has no passwordEnv:
SEED_PASSWORD='…' lunora auth seed accounts.json --password-env SEED_PASSWORDA password comes only from an environment variable. A named variable that is unset or empty fails the run before any request, and the output lists the variable's name, never its value. --dry-run validates the file and prints the plan without sending anything; with --format json the plan is in data.plan.
To seed a deployed worker, pass its URL and confirm the target:
LUNORA_ADMIN_TOKEN='…' lunora auth seed accounts.json --prod --url https://staging.example.com --yesPrefer LUNORA_ADMIN_TOKEN over --token, which other local processes can read from the process table. Without --yes a non-local target asks for confirmation, and a non-interactive shell refuses.
What a run does
For each user the plane runs ensureUser:
- A missing user is created. When the
inviteOnly()plugin is enabled, the plane first mints a short-lived sign-up invitation, so the create is admitted. A pending invitation already sent for the address is used as it is, and a create that fails leaves the invitations as they were. - An existing user is never re-invited. Its password is set (a credential account is linked when it has none), and its role,
emailVerifiedanddataare written.
Then, for each organization, the command finds it by slug or creates it with its owner, gives a found one the file's name when it differs, and makes sure every listed member, the owner included, holds the given role. It lists organizations and members to the last page, so one past the first page is found rather than added again. A worker without the organization capability skips organizations with a message.
Every failure is reported by name and the run exits non-zero after the remaining accounts have been tried. The exit codes apply.
Run it from CI
The following job step seeds a staging worker after a deploy, taking every secret from the repository's secret store:
- name: Seed staging accounts
env:
LUNORA_ADMIN_TOKEN: ${{ secrets.STAGING_ADMIN_TOKEN }}
SEED_PASSWORD: ${{ secrets.STAGING_SEED_PASSWORD }}
run: pnpm exec lunora auth seed accounts.json --password-env SEED_PASSWORD --prod --url https://staging.example.com --yesSeed from code instead
The same operation is a method on the trusted admin plane and on the client, for a test suite that seeds in beforeAll:
import { LunoraAdminClient } from "@lunora/client/admin";
declare const admin: LunoraAdminClient;
const { created, user } = await admin.ensureAuthUser({ email: "ada@example.com", name: "Ada", password: process.env.SEED_PASSWORD, role: "admin" });It posts to POST /_lunora/admin/auth/users/ensure and returns { created, user }; the password is never returned.
See also
@lunora/auth, forcreateAuthAdminand the invite-only plugin.lunora authin the CLI reference.