What are User Roles?
StockAPI implements role-based access control (RBAC) to manage user permissions. Each user is assigned a role that determines what actions they can perform within the system. Roles are defined when a user is created and are included in the JWT token payload, allowing the API to verify permissions on each request.User Model Structure
The user model defines the role field with a default value:If no role is specified during user creation, the user is automatically assigned the “vendedor” role.
Available Roles
StockAPI supports the following user roles:vendedor
Seller/Sales RepresentativeThe default role for standard users. Designed for employees who need to manage products and create orders in daily operations.
developer
Developer/AdministratorAdvanced role with full system access. Intended for technical staff and system administrators.
Role Capabilities
Vendedor (Seller)
The “vendedor” role is designed for day-to-day business operations:Product Management
Product Management
- Create new products
- View product details
- Update existing products (price, stock, etc.)
- Delete products
- Search for products
Order Management
Order Management
- Create new orders
- View all orders
- Delete orders
- Automatic stock deduction upon order creation
Stock Management
Stock Management
- Update product stock levels
- View current stock information
- Receive automatic stock updates when orders are created
Developer (Administrator)
The “developer” role has the same capabilities as “vendedor” with additional system-level access:All Vendedor Capabilities
All Vendedor Capabilities
Developers have full access to all product and order management features available to sellers.
System Administration
System Administration
- Access to system configuration
- Ability to manage environment variables
- Database management capabilities
- Monitoring and debugging access
User Management
User Management
While user creation is manual through scripts, developers have the ability to:
- Create new users via
createUserScript.js - Assign roles to users
- Manage user credentials
Creating Users with Roles
Users are created manually using thecreateUserScript.js utility. The role is specified as the third parameter:
Creating Different Role Types
Role Information in Tokens
When a user logs in, their role is included in the JWT token payload:Role Verification
The role information is extracted from the JWT token by theverifyToken middleware:
req.user.role for implementing role-specific logic.
Current Implementation
In the current implementation, both “vendedor” and “developer” roles have access to all protected endpoints. The role system provides a foundation for future fine-grained permission controls.
- Both roles can create, read, update, and delete products
- Both roles can create and manage orders
- Role differentiation is primarily organizational
Future Enhancements
The role system is designed to support future permission controls such as:Granular Permissions
Restrict certain actions to specific roles (e.g., only developers can delete products)
Custom Roles
Add new roles like “manager”, “auditor”, or “inventory-staff” with specific permissions
Role Hierarchy
Implement role inheritance where higher roles have all permissions of lower roles
Action Logging
Track which role performed which action for audit purposes
Best Practices
Assign Appropriate Roles
Give users the minimum role required for their job function. Most sales staff should have the “vendedor” role.
Limit Developer Accounts
Only create “developer” role accounts for technical staff who need system-level access.
Regular Audits
Periodically review user accounts and their assigned roles to ensure they’re still appropriate.
Role Comparison
| Feature | Vendedor | Developer |
|---|---|---|
| Create Products | ✅ | ✅ |
| View Products | ✅ | ✅ |
| Update Products | ✅ | ✅ |
| Delete Products | ✅ | ✅ |
| Create Orders | ✅ | ✅ |
| View Orders | ✅ | ✅ |
| Delete Orders | ✅ | ✅ |
| System Access | ❌ | ✅ |
| Create Users | ❌ | ✅ |
| Database Access | ❌ | ✅ |
Next Steps
JWT Tokens
Learn how to obtain and use authentication tokens
Products API
Start using the API to manage products