Skip to main content

Data Models

@rapidrest/auth provides four data models. Each has a Mongo and a SQL implementation, distinguished by a Mongo/SQL suffix on the class name — e.g. User becomes UserMongo for MongoDB projects, UserSQL for PostgreSQL/SQLite ones, matching the convention used throughout @rapidrest/service-core. Import them from the matching subpath: @rapidrest/auth/mongo or @rapidrest/auth/sql.

User

The account itself.

FieldTypeNotes
rolesstring[]Persisted. Same roles consumed by @RequiresRole and ACL checks elsewhere in the framework.
scopesstring[]Not persisted — purposefully built at runtime (from the strategy/JWT), not stored in the database.
verifiedbooleanWhether the account's contact info (email/phone) has been verified.

User implements service-core's JWTUser, so an authenticated User is exactly what @User injects into your route handlers elsewhere in the framework. It's locked down by @Protect by default — anonymous and every role are denied unless you override the ACL yourself.

Alias

An alternate identifier for a user account: an email address, a phone number, a display name, or a third-party OAuth provider ID.

FieldTypeNotes
aliasstringThe identifying value itself. Marked @Identifier, unique-indexed.
typeAliasTypeEMAIL, NAME, OAUTH, or PHONE.
userUidstringForeign key to the owning User.
verifiedboolean

A user can have multiple aliases — e.g. an email alias and a Google OAuth alias both pointing at the same User. Login flows that resolve "who is this" (basic, OTP, OIDC) look the caller up by alias.

Secret

An authentication secret tied to a user — a hashed password, a TOTP seed, or a WebAuthn credential.

FieldTypeNotes
dataanyShape depends on type: a password hash string, a TOTPSecret object, or a StoredPasskeyCredential object.
typeSecretTypeFIDO2, PASSKEY, PASSWORD, or TOTP.
userUidstring

For WebAuthn secrets (fido2/passkey), the Secret's own uid is set equal to the WebAuthn credential ID, so login-time verification can look it up directly by credential ID rather than scanning a user's secrets.

data is always stripped from API responses — see BaseSecretRoute for how secrets are created and returned safely.

Profile

Additional, personally identifying information about a user.

FieldTypeNotes
avatarstring?
birthdateDate?
contactsContact[]{contact, type: EMAIL|PHONE, verified}. Gated behind @RequiresScope("profile:email") — see Models & Persistence → @RequiresScope.
givenNamestring?
familyNamestring?
preferencesPreferences{contact: string[]}. Gated behind @RequiresScope("profile:preferences").

A Profile's uid must equal its owning User's uid — it's a 1:1 extension of the account, not a separately-identified resource.

AuthResult

Not a persisted model — the response DTO every auth-flow route returns on success:

interface AuthResult {
token: string;
user: User;
}

token is a JWT minted via JWTUtils.createToken, using the same auth config every other part of the framework uses (see Configuration).