Skip to Content

Users

Users are the people who sign in to your project. Foir keeps each user’s identity and profile, and segment rules read them to personalize what each user sees.

Overview

A user is someone who visits your site, signs in, and interacts with your content. Foir keeps for each one:

  • Identity: the addresses they are known by, how they sign in, and when the account was made
  • Profile: their name, their picture and the language they read in, which the user sets themselves with updateMyProfile and a manager with updateUser
  • Owned data: data you model as an ordinary model owned by its user (access.ownerPlane: 'user')
  • Status: ACTIVE, PENDING or SUSPENDED. A user is PENDING until they hold a way to sign in: a password, a connected sign-in, or an address they proved with a code. A user made without a password starts there. A deleted user keeps their id, with no name or address, so what they made still names them.

Users are central to personalization. Segment rules are evaluated against a user’s attributes on every request, and targeting rules can check whether anyone is signed in.

Users and organizations

Every user belongs to one pool, the boundary their sign-in is shared within, and never moves to another. A project has its own pool. In a project that uses organizations, an organization can also sign its own people in, and then has a pool of its own, started when it is made (see an organization that signs its own people in). Where a user may act is a separate thing, a membership: one for each place they stand at, holding the roles they have there.

  • A user of the project’s pool can hold memberships of the project and of any of its organizations. The people who run your tenants are users of this kind: they keep one sign-in and may act for several organizations.
  • A user of an organization’s own pool can hold memberships of that organization and of the organizations beneath it, and of nowhere else.

An address belongs to one user per pool. The same address in two pools is two users, so alice@example.com may be a user of the project and of an organization’s own pool, while two users of the project’s pool cannot both hold it.

What a read returns depends on where the caller stands, and the project key is the case that surprises people:

CallerUsers it reads
A project key, or a console session standing at the projectthe users of the project’s pool only, none of any organization’s own
A key confined to an organization, a project key naming one with X-Org-Id, or a console session standing at onethe users of that organization’s pool, of every organization nested under it, and of the project’s
A project key sending X-Org-Reach: project with organizations:reachevery organization’s users and the project’s, on a read

So an ancestor reads its descendants’ users, and a descendant reads none of its ancestors’. Changing or deleting a user is narrower: a caller standing in an organization changes only the users of that organization’s own pool, never a descendant’s and never one of the project’s. See what a credential with no organization reads and Organization Trees for the rule itself.

Deleting an organization removes its own pool’s users along with the rest of its data when the deletion window closes. Users of the project’s pool are not the organization’s to remove, including the people who acted for it: only their memberships of it go.

In the console

Managing users

  1. Go to Access > People in the console
  2. Browse the list of users, with columns for email, status, last sign-in and creation date
  3. Click a user to open their detail page

User detail

The detail page has three tabs:

  • Overview: name, email, roles, the organizations they belong to, status, last sign-in, and when the account was made and last changed
  • Notifications: the notifications sent to the user
  • Preferences: their notification preferences, including whether email to them was suppressed after a bounce or a complaint, and the switch that restores it

User-owned data

To store custom data on each user, model it as an ordinary model whose records are owned by the user who created them. Set the model’s Owner plane to User (access.ownerPlane: 'user'): each user then owns their own records, kept apart from everyone else’s. Mark the model as a singleton to give each user exactly one record, a profile.

Defining the model

  1. Add a model with the fields you need (e.g., companyName, tier) to your foir.config.ts
  2. Set its access to ownerPlane: 'user' and visibility to private
  3. Run foir push to apply it

See Defining Models → Model Access for the full access shape.

Editing a user’s record

  1. Open the user-owned model under Content > Models and view its records
  2. Filter to the user whose record you want
  3. Create or update their record and save

User-owned data is available in segment rules and can be used to drive personalization.

Via the CLI

Managing users

# List users foir users list # Get a user by ID or email foir users get <id> foir users get jane@example.com # Create a user (email is required; pass extra fields with -d/--data) foir users create --email new@example.com # Delete a user (type their address to confirm) foir users delete <id> --confirm-email jane@example.com

foir users list has an Organization column naming the organizations each user is a member of, or project-shared for a user who belongs to the project alone. It lists what the request reaches: the users of the project’s pool plus those of the organization the credential is confined to, or the one the command stands in, and everything nested under it. users list has no flag of its own to pick an organization: the global --org-id, or foir context switch-org, stands the command in one. An id in that column, where other rows show a name, is an organization whose name this credential cannot read.

User-owned data

User-owned data is an ordinary model: its structure lives in foir.config.ts and is applied with foir push, and its records are managed with the standard foir records commands.

Define a user-owned model in your config:

import { defineConfig, defineModel } from '@foir/cli/configs'; export default defineConfig({ key: 'my-app', name: 'My App', models: [ defineModel({ key: 'profile', name: 'Profile', fields: [ { key: 'companyName', label: 'Company', type: 'text' }, { key: 'tier', label: 'Tier', type: 'text', queryable: true }, ], access: { ownerPlane: 'user', defaultVisibility: 'private', }, }), ], });
# Apply the model definition foir push # List and inspect records of the user-owned model foir records list profile foir records get profile <id> # Create or update a record foir records create profile --data '{ "companyName": "Acme Corp", "tier": "enterprise" }'

Via the API

Querying users

Listing users takes users:read.all, and looking up one user takes users:read.named, which users:read.all also covers. Only an admin key may hold them, or an operation that declares them for the users its work is about: a publishable or a server key is refused them when it is made, and a request signed in as one of the project’s users is refused both, whatever its key holds. Look up a single user by id or by email, or list with an optional filter (search matches email; status filters by ACTIVE / PENDING / SUSPENDED).

query GetUser { user(id: "usr-123") { id email status createdAt } } query FindUsers { users(filter: { search: "jane@example.com" }, first: 10) { edges { node { id email status } } } }

A user is not one of your models, so on the data client both reads are users namespace operations, named after the GraphQL field. A namespace result comes back verbatim, so include and omit do not apply:

const user = await foir.ns.users.user({ id: 'usr-123' }); const found = await foir.ns.users.users({ filter: { search: 'jane@example.com' }, first: 10, });

User-owned data

A user-owned model is queried through the normal typed record API. The generated type exposes _id plus each field you configured (e.g. companyName, tier) as typed fields. Because the model is owned by the user plane, a user can only ever read and write their own records.

For a user-owned singleton, the signed-in user reads and writes their one record with the generated my<Model> query and setMy<Model> mutation. They reach only that user’s own record, and are gated like any read and write of the model, on records:read and records:write for it. For the profile model above that is myProfile / setMyProfile:

# The signed-in user's own record query Me { myProfile { _id companyName tier } } mutation SaveMe { setMyProfile(input: { companyName: "Acme Corp", tier: "enterprise" }) { _id companyName } }

my<Model> and setMy<Model> are the findMine and setMine operations on the data client — the same pair, addressed by the model key rather than by the generated field name. Both need a user’s bearer token, not just an API key:

const profile = await foir.profile.findMine(); await foir.profile.setMine({ input: { companyName: 'Acme Corp', tier: 'enterprise' }, });

Your back-office tooling reads user-owned records with an admin key through the standard typed model queries, which return every owner’s records scoped by the key’s permissions:

query Profiles { profiles(where: { tier: { eq: "enterprise" } }, first: 10) { edges { node { _id companyName tier } } } }

The same read through the data client is an ordinary findMany on the model:

const profiles = await foir.profile.findMany({ where: { tier: { eq: 'enterprise' } }, first: 10, });

Records for one user

Content records can be scoped to individual users, so you can store content for one person such as saved preferences, a personalized landing page, or settings of their own. A record scoped to a user is only returned when that user is signed in.

Your users’ account page

A signed-in user manages their own account through your app, with their own bearer token. None of these asks a permission, and each acts only as the user signed in. The same calls are in @foir/sdk/auth.

What the page shows or doesQuery or mutation
Their name, picture and languageupdateMyProfile(firstName, lastName, avatarUrl, preferredLocale)
Their email addresses, add one, make one primary, remove onemyAddresses, addMyAddress(email, password) and its step, makeMyAddressPrimary(email), removeMyAddress(email)
Where they are signed in, and sign out of onemySessions, endMySession(id)
Sign out of every device and app, keeping this onesignOutEverywhere(keepThis: true)
The providers they sign in withmySignInMethods, disconnectSignInMethod(provider)
Connect another providerconnectSignInMethod(provider, returnTo)
The apps they have authorised, and take one backmyAuthorizedApps, revokeAuthorizedApp(id)
A personal access tokencreatePersonalAccessToken(name, expiresInDays)
Their passkeys, second factors and recovery codesmyFactors, and the step-up below
Leave an organization, or the projectleaveMembership
A copy of their dataexportMyData
Close the accountdeleteMyAccount

connectSignInMethod answers the provider’s address to send the browser to. The browser comes back to returnTo with connected naming the provider, or connect_error naming why it was refused, for example sign_in_method_held when the provider’s account already signs in as somebody else. returnTo has to be beneath the app address your project (or the user’s organization) sets as its brand’s app base URL.

Email addresses

A user can sign in with more than one address. addMyAddress sends a six-digit code to the new address and answers a step: its id, a token minted for that step alone, and when it stops working, ten minutes on. Your page posts the code back to the step’s own route, with the token in the body and no bearer token or key:

POST /v1/address-proofs/{id} Content-Type: application/json {"token": "…", "code": "123456"}

The answer is the address, added and proven. Until then it isn’t on the account and signs nobody in. proveMyAddress in @foir/sdk/auth makes this post for you.

The step finishes once, for the user who began it, and only while the session that began it is live: signing out, or a password reset that signs them out everywhere, ends it. Adding the address again begins a new step and ends the old one.

An address is a way into the account, since a sign-in code or a password reset can go to it. So:

  • Adding one asks for the user’s current password. An account with no password, one that signs in only with a provider or a passkey, needs a sign-in in the last ten minutes instead. A personal access token never counts as one.
  • Nobody’s address is taken. If another account in the project holds the address, proven or not, the step refuses it once the code is right.
  • The address the account uses is told each time another one is added.
  • A user is sent at most five codes an hour, and five wrong codes spend one.

The primary address is the one shown for the user and the one mail goes to. makeMyAddressPrimary moves it to another proven address and tells the old one. The primary address can’t be removed, so removeMyAddress refuses it until another one is primary.

A copy of their data

exportMyData answers one JSON document in the foir.my-data.v1 format. It holds the user’s account: their profile, addresses, memberships with the roles held at each, the providers they sign in with, the apps they authorised, their sessions and tokens, and their notification preferences. It also holds everything deleting the account would erase: the records they own, each with the content it holds now (a draft included), and the files they own, each with the address its bytes are at. No password, code or token value is in it.

The console’s account page offers the same to your team as Download a copy.

Deleting the account

deleteMyAccount erases the user’s account: their name, addresses and sign-ins go, and they’re signed out everywhere. The records and files they own are deleted, just after it answers, and the answer counts them. An account with a password gives it. An account with none sets confirm, and needs a sign-in in the last ten minutes. A personal access token never counts. In an app that holds the user’s session, deleteMyAccountAndSignOut in @foir/sdk/auth makes the call and clears the session.

The console’s account page offers the same to your team, as Delete your account. It’s refused while the account is the last manager of a workspace, naming the workspace.

Leaving

leaveMembership ends the user’s own membership where the request stands: the organization named in X-Org-Id, or, with none, the project’s own. Every role they hold there ends with it. Their account and everything they made stay, and coming back takes a new invitation. It answers false when they held no membership there.

It’s refused, with the reason, in two cases:

  • They’re the only member of the organization who can staff it. Somebody else there needs a role with members:write first.
  • It’s the last place they stand in the project. A project’s people sign in only where they stand, so leaving it would lock them out of their own account. deleteMyAccount is how a user leaves altogether.

The console’s account page offers the same to your team, workspace by workspace and project by project. A console user may leave every workspace, because they still sign in to the console. A workspace’s last manager stays until somebody else manages it.

Personal access tokens

A personal access token is a user’s own standing credential, for a script or a tool that calls your API as them. It is shown once, when it is made, lasts from 1 to 365 days, and is revoked with endMySession, as a session is. It is sent beside your app’s key, as Authorization: Bearer foir_pat_…, and carries what the user’s roles give them where it is used, never more. Signing out everywhere leaves it, and a password reset ends it.

Passkeys and second factors

A user can hold passkeys, an authenticator app, security keys and a set of recovery codes. A passkey signs them in on its own, with their fingerprint, face or device PIN. An authenticator app or a security key is a second factor, asked for after their password. myFactors lists what they hold, each with a kind (passkey, totp, security_key or recovery_codes) and the id a removal takes. For recovery codes, remaining says how many are unused.

Every change spends a proof the user’s session made in the last ten minutes on Fóir’s hosted step-up page: their password, and their second factor where they hold one. Without one, the change is refused with STEP_UP_REQUIRED, extensions.stepUp of proof, and the page in extensions.stepUpUrl. Send the user there with return_to added to the page’s query, and ask the change again when they come back. return_to is admitted only under the origins your app declares, or its landing page. stepUp answers the same page before any change. A proof pays for one change, and proving a second factor also counts the session as two factors, so an operation that asks for a second factor runs for it.

The page’s address carries a token minted for the user’s session alone, in its fragment, so it reaches no server. It ends with the session: signing out, or a password reset that signs the user out everywhere, ends it.

Adding an authenticator app:

mutation { beginFactorEnrollment(method: "totp") { step { id token } totpSecret totpQr } }

Refused with STEP_UP_REQUIRED until the session has proved it on the page; after that it answers the step.

beginFactorEnrollment answers a step beside what the authenticator needs. What the authenticator makes goes back to the step’s own route, with the step’s token in the body and no bearer token or key, within ten minutes:

POST /v1/factor-enrollments/{id} Content-Type: application/json {"token": "…", "totpCode": "123456"}

completeFactorEnrollment in @foir/sdk/auth makes this post for you:

import { beginFactorEnrollment, completeFactorEnrollment, stepUpRequired } from '@foir/sdk/auth'; try { const begun = await beginFactorEnrollment(env, { method: 'totp' }, { bearerToken }); await completeFactorEnrollment(env, { step: begun.step, totpCode: '123456' }); } catch (err) { const asked = stepUpRequired(err); if (asked?.url) { const page = new URL(asked.url); page.searchParams.set('return_to', window.location.href); window.location.assign(page.toString()); } }

The step finishes once, for the user who began it, and only while the session that began it is live. Beginning another ends it.

For a passkey method is passkey, and for a security key webauthn. Pass the answer’s webauthnOptionsJson to navigator.credentials.create and send the result as webauthnAttestationJson; a security key also takes a name (displayName on the route). A proof pays for removeFactor(kind, id) or makeRecoveryCodes the same way. renameFactor(kind, id, name) renames a security key or passkey and needs no proof, because a name proves nothing.

makeRecoveryCodes answers the codes once. They replace any the user held, and each one stands in for their second factor at one sign-in. Codes stand in for a second factor, so a user needs one to have them, and removing the last removes the codes too.

A passkey answers for the site it was added at. On Foir’s own login page, after a user signs in with their password, the page offers to add one when they hold neither a passkey nor a second factor; skipping it stops the offer on that browser for 30 days. The console’s account page adds them for your workspace’s team. The login page offers “Sign in with a passkey” beside the password. A passkey that verified its holder counts as two factors. One that did not is one factor, and a user who holds a second factor is asked for it next.

A user’s password manager lists each passkey under your project’s name, as your login page shows it, with their address beside it. Where the user’s organisation sets a display name, the passkey takes that name instead. Every project shares the one site on Foir’s login page, so the name is how a user tells their passkeys for different projects apart. Outside production the name also gives the environment, for example Jacket (DEV).

Your project’s custom login domain is another site to the browser, so it has passkeys of its own. After a user signs in there with their password, the page offers a passkey for that domain when they hold none on it, and “Sign in with a passkey” sits beside the password. A passkey made there signs in on that domain only. It always verifies its holder, so it counts as two factors. myFactors lists it with the domain as its name, and removeFactor removes it. Removing the domain removes the passkeys made on it, and their holders sign in another way. A passkey a user made on Foir’s login page before you added the domain doesn’t move to it, so they add one on the domain.

Once a user holds a second factor, the login page asks for it after their password, whatever your app requires, and offers a recovery code in its place. A sign-in by an emailed code or a provider proves no second factor, so it is refused for that user with two_step_sign_in, and they sign in with their password or a passkey.

Best Practices

  • Model user-owned data early: decide what custom data you need on users, and define a user-owned model for it, before launch.
  • Use email as a natural identifier: the CLI looks users up by email directly.
  • Manage account lifecycle with status: use SUSPENDED to disable accounts without deleting them.
Last updated on