Users
The users
collection is a multi-entry collection that stores users and is tightly bound with the authentication and API guard functionalities.
Definition
The collection includes the following fields, with required fields indicated by the R symbol:
Field | Type | Description |
---|---|---|
| Determines the user's login access to the CMS. | |
| Administrators have all privileges within the CMS, regardless of their role and capabilities. | |
| The user's first name. | |
| The user's last name. | |
| A unique email address is assigned to users, serving as their login credential. | |
| The user's password is stored in the database as a hash using Argon2. | |
| Defines the user's base capabilities within the CMS. | |
| List of capabilities granted to the user in addition to their role capabilities. | |
| The preferred language for the dashboard interface (experimental feature). | |
| The preferred format for displaying date strings in the dashboard. | |
| The preferred format for displaying time strings in the dashboard. | |
| An automatically generated timestamp indicating when the user was created. | |
| An automatically generated timestamp indicating when the user was last updated. | |
| The unique identifier of the record. |
Check out the collection definition on GitHub for more details.
Roles and capabilities
User capabilities allow users to perform specific actions through the API. Pruvious has predefined the following capabilities:
Capability | Description |
---|---|
| Specifies if the user can access the CMS dashboard. |
| Specifies if the user can clear the cache using the /api/clear-cache API endpoint. |
| Automatically generated capability that allows users to create individual records in a multi-entry collection. |
| Automatically generated capability that allows users to create multiple records in a multi-entry collection. |
| Automatically generated capability that allows users to read individual collection records. |
| Automatically generated capability that allows users to read multiple records in a multi-entry collection. |
| Automatically generated capability that allows users to update individual collection records. |
| Automatically generated capability that allows users to update multiple records in a multi-entry collection. |
| Automatically generated capability that allows users to delete individual records in a multi-entry collection. |
| Automatically generated capability that allows users to delete multiple records in a multi-entry collection. |
| Specifies if the user can update their profile using the /api/profile API route. |
You can specify additional capabilities in your nuxt.config.ts
file as follows:
# nuxt.config.ts
export default defineNuxtConfig({
modules: ['pruvious'],
pruvious: {
customCapabilities: ['manage-api-keys', 'send-emails'],
},
})
Guards
Guards are security layers that are triggered during certain CRUD operations on collections and fields. They can be added to collection and field definitions by using the guards
property. Here's an example:
# collections/api-keys.ts
import { defineCollection, hasCapability } from '#pruvious'
export default defineCollection({
name: 'api-keys',
label: 'API Keys',
mode: 'single',
guards: [
async ({ user }) => {
if (!hasCapability(user, 'manage-api-keys')) {
throw new Error('You are not allowed to manage API keys')
}
},
],
fields: {
cloudflare: {
type: 'text',
options: {},
},
},
})
Last updated on January 6, 2024 at 12:45