Overview
StockPro’s user management system allows administrators to create employee accounts with different permission levels. Each user has their own authentication credentials and assigned role that determines their system access.User management requires administrator privileges. Only admin users can create new employee accounts.
Understanding User Roles
StockPro supports three distinct user roles, each with different access levels:Admin
- Full system access
- Can manage users and configuration
- Access to all reports and analytics
- Can modify business settings
- Recommended for: Business owners, IT administrators
Gerente (Manager)
- Operational management access
- Can view reports and analytics
- Manage inventory and products
- Process and review sales
- Cannot modify system configuration
- Recommended for: Store managers, supervisors
Empleado (Employee)
- Basic operational access
- Process sales transactions
- View inventory
- Add products
- Limited access to reports
- Cannot modify settings or manage users
- Recommended for: Sales staff, cashiers
Creating a New User
Access Employee Creation Form
Navigate to the employee creation interface (typically accessible from the configuration panel or user management section for administrators).
Enter User Information
Fill in the required user details:Required Fields:
- Name (
name): Employee’s full name - Email (
email): Valid email address for authentication - Password (
password): Secure password for the account - Tipo (
tipo): User role selection (admin, gerente, empleado)
How User Creation Works
The user creation process involves several steps managed byagregar_empleado.js:
Step 1: Email Validation
Before creating an account, the system checks if the email is already in use:agregar_empleado.js:16-26
If the email is already registered, the system will detect it and prevent duplicate accounts.
Step 2: Create Firebase Authentication Account
A new Firebase Authentication account is created with the provided email and password:agregar_empleado.js:29-30
- Firebase creates an authentication account
- Returns user credentials with unique
uid - Password is securely hashed by Firebase
- User can immediately log in with these credentials
Step 3: Store User Profile
User details are saved to the Firestoreusuarios collection:
agregar_empleado.js:32-39
uid: Firebase Authentication user ID (unique identifier)name: User’s display nameemail: User’s email addresstipo: Role type (admin, gerente, empleado)
The
usuarios collection stores user profiles and permissions. See Firestore Collections for complete schema details.Step 4: Confirmation
Upon successful creation, the system displays a confirmation alert:agregar_empleado.js:41
Error Handling
The user creation process includes error handling for common issues:agregar_empleado.js:42-45
Common Errors
Email Already in Use
Email Already in Use
Error:
auth/email-already-in-useCause: The email address is already registered in Firebase AuthenticationSolution: Use a different email address or reset the existing account’s passwordWeak Password
Weak Password
Error:
auth/weak-passwordCause: Password doesn’t meet Firebase’s minimum requirements (usually 6 characters)Solution: Choose a stronger password with at least 6 charactersInvalid Email
Invalid Email
Error:
auth/invalid-emailCause: Email format is invalidSolution: Verify email format is correct (e.g., [email protected])Firestore Permission Denied
Firestore Permission Denied
Error:
permission-deniedCause: Firestore security rules don’t allow writing to usuarios collectionSolution: Verify security rules allow authenticated admins to create user documentsBest Practices
Use Strong Passwords
Enforce strong password policies for all employee accounts to maintain security
Assign Appropriate Roles
Give users the minimum permissions needed for their job functions
Use Work Emails
Use company email addresses for better accountability and password recovery
Document User Changes
Keep a record of when users are added or their roles change
Security Recommendations
- Role Segregation: Don’t give admin access to regular employees
- Password Policies: Require passwords to be changed periodically
- Email Verification: Consider enabling Firebase email verification for new accounts
- Activity Logging: Monitor user actions for suspicious activity
- Regular Audits: Review user accounts periodically and remove inactive users
Managing Existing Users
Viewing User List
Currently, user management is handled through Firebase Console. To view all users:- Go to Firebase Console
- Select your project
- Navigate to Authentication > Users
- View all registered users and their details
Modifying User Roles
To change a user’s role type:- Access Firestore in Firebase Console
- Navigate to the
usuarioscollection - Find the user document by email or uid
- Edit the
tipofield (admin, gerente, or empleado) - Save the changes
Changes to user roles take effect on their next login or page refresh.
Deleting Users
To remove a user from the system:- Delete from Authentication: Firebase Console > Authentication > Select user > Delete
- Remove from Firestore: Delete the corresponding document in the
usuarioscollection
Integration with Security Rules
User roles are enforced through Firestore security rules. See Security Rules for details on configuring role-based access control. Example security rule for role-based access:firestore.rules
Troubleshooting
User Can’t Log In After Creation
Check:- Verify email and password are correct
- Confirm account exists in Firebase Authentication
- Check that user document exists in
usuarioscollection - Verify Firestore security rules allow read access
Role Permissions Not Working
Check:- Confirm
tipofield in Firestore matches role name exactly - Verify security rules are correctly checking user roles
- Ensure user has logged in again after role change
Email Verification Issues
Check:- Firebase Authentication email verification settings
- Email provider spam filters
- Firebase project sender email configuration
Related Resources
Authentication API
Technical documentation for createUserWithEmailAndPassword and other auth functions
Firestore Collections
Complete schema for usuarios collection
Security Rules
Configure role-based security rules
Configuration Panel
Access user management from the configuration interface