Users
Manage your product's end users with Spica, from sign-up and login to email and phone verification, password reset, passwordless login and bans.
Users are the end users of your product. They log in with a username and password, a one-time code or magic link, or an OAuth provider, and they reach your data through policies and bucket rules.

Create users
POST /passport/user requires an identity or an API key with the passport:user:create action. Users can't call it anonymously, so sign-up goes through your backend, typically an HTTP function:
curl -X POST https://api.example.com/api/passport/user \
-H "Authorization: APIKEY <key>" -H "Content-Type: application/json" \
-d '{"username": "reader1", "password": "readerPass1"}'{"username": "reader1", "policies": [], "_id": "6b0b1adea5611972c29c2631"}| Field | Description |
|---|---|
username | Required. At least 3 characters, unique. Often an email address. |
password | Required. Checked against the password policy. |
bannedUntil | Optional date until which the user can't log in. |
deactivateJwtsBefore | Optional Unix timestamp in seconds. Tokens issued before it are rejected. |
Then attach the policies users need, for example a policy that allows reading and writing your app's buckets:
curl -X PUT https://api.example.com/api/passport/user/<userId>/policy/<policyId> \
-H "Authorization: APIKEY <key>"The number of users can be limited with --passport-user-limit. Account creation is rate limited by the createUser rate limit.
Log in
/passport/logincurl -X POST https://api.example.com/api/passport/login \
-H "Content-Type: application/json" \
-d '{"username": "reader1", "password": "readerPass1"}'{"scheme": "USER", "token": "eyJhbGciOiJIUzI1NiIs..."}Use the token as Authorization: USER <token>. Its payload contains the user's _id, username and policies, which rules can read through auth. The response also sets a refresh token cookie, see Tokens & sessions.
What users can do on their own account
Without any extra policy, a logged-in user can:
| Endpoint | Purpose |
|---|---|
GET /passport/user/:id | Read their own record. |
PUT /passport/user/:id/self | Change their password: {"password": "..."}. |
POST /passport/user/:id/start-factor-verification, .../complete-factor-verification, DELETE .../factors | Manage two-factor authentication. |
Everything else needs a policy. Attaching an email address or phone number to an account requires passport:user:update, so run it from a function with an API key after you have verified the user's token.
Email and phone verification
Users can prove ownership of an email address or a phone number, which then enables password reset and passwordless login through that channel.
Emails are sent through the mailer and SMS through Twilio. Enable the provider and strategy in the user configuration:
{
"providerVerificationConfig": [
{"provider": "email", "strategy": "Otp"},
{"provider": "phone", "strategy": "Otp"}
]
}| Strategy | What the user receives |
|---|---|
Otp | A 6-digit code, by default Your verification code is: 123456. |
MagicLink | A link to <public-url>/passport/user/verify-magic-link?token=.... |
Start and complete the verification:
curl -X POST https://api.example.com/api/passport/user/<userId>/start-provider-verification \
-H "Authorization: APIKEY <key>" -H "Content-Type: application/json" \
-d '{"value": "ada@example.com", "provider": "email", "strategy": "Otp", "purpose": "verification"}'
curl -X POST https://api.example.com/api/passport/user/<userId>/verify-provider \
-H "Authorization: APIKEY <key>" -H "Content-Type: application/json" \
-d '{"code": "123456", "provider": "email", "strategy": "Otp", "purpose": "verification"}'The number of attempts is limited by verificationProcessMaxAttempt, and codes expire after --passport-user-verification-code-expires-in seconds (5 minutes by default).
Password reset
Enable a provider in the user configuration:
{"resetPasswordProvider": [{"provider": "email", "strategy": "Otp"}]}Then let the user request a code and set a new password. Neither call needs a token:
curl -X POST https://api.example.com/api/passport/user/forgot-password/start \
-H "Content-Type: application/json" \
-d '{"username": "reader1", "provider": "email"}'
curl -X POST https://api.example.com/api/passport/user/forgot-password/verify \
-H "Content-Type: application/json" \
-d '{"username": "reader1", "code": "123456", "newPassword": "aNewPassword1", "provider": "email"}'Without the configuration the API responds with Provider or Reset password is not configured properly.
Passwordless login
Enable it in the user configuration:
{"passwordlessLogin": {"passwordlessLoginProvider": [{"provider": "email", "strategy": "Otp"}]}}curl -X POST https://api.example.com/api/passport/user/passwordless-login/start \
-H "Content-Type: application/json" \
-d '{"username": "reader1", "provider": "email"}'
curl -X POST https://api.example.com/api/passport/user/passwordless-login/verify \
-H "Content-Type: application/json" \
-d '{"username": "reader1", "code": "123456", "provider": "email"}'The verify call returns a user token like a normal login. Both endpoints are rate limited by the login rate limit.
Ban users and revoke sessions
| Goal | How |
|---|---|
| Block logins until a date | PUT /passport/user/:id with bannedUntil. |
| Invalidate every token issued so far | PUT /passport/user/:id with deactivateJwtsBefore set to the current Unix time. |
| Remove the account | DELETE /passport/user/:id. |
The auth devkit offers ban and deactivateUserTokens helpers.
Manage users
| Endpoint | Action |
|---|---|
GET /passport/user | passport:user:index |
GET /passport/user/:id | passport:user:show |
POST /passport/user | passport:user:create |
PUT /passport/user/:id | passport:user:update |
DELETE /passport/user/:id | passport:user:delete |
PUT /passport/user/:id/policy/:policyId | passport:user:policy:add |
DELETE /passport/user/:id/policy/:policyId | passport:user:policy:remove |
Identities or users?
Use users for anyone who signs up to your product. Use identities only for people who operate the backend. Users never see the panel, and identities never pass through bucket rules.