A user model is a regular model, with the only difference being that it represents a real-world user role in the application. User models have the following features:
User models have credential fields that are used for authentication.
A field marked as
@publicCredential can be any user identifier that can be used for authenticating the user (usernames, emails, or phone numbers). Public credentials can be used to identify a user publicly among other users.
A field marked with
@secretCredential on the other hand, should not be shared with other users, and it is used only in the authentication process, along with a public credential.
Pragma encrypts the values of fields annotated with
@secretCredential using the application secret before storing them in the database.
You can define roles for user models to specify what each kind of user is allowed to perform. See Permissions for more details.
To create a user model, simply annotate a model with the
@user directive. For example:
This tells Pragma to setup authentication flows for the
User user model, where the
password are the user's credentials.
You can mark multiple fields with the
@publicCredential directive. However, there can only be one
@secretCredential field on a model. This allows for functionality such as allowing users to either log in using their email, or their username. For example:
See the Generated API section for more details on how to use