Authentication System
PROVESA Web implements a secure authentication system with:- Email/Password Login: Standard credential-based authentication
- Password Recovery: Email-based password reset flow
- Session Management: Secure session handling with Better Auth
- Route Protection: Admin routes protected by authentication middleware
User Roles
Currently, PROVESA Web supports a single admin role:| Role | Access Level | Description |
|---|---|---|
| Administrator | Full Access | Complete control over all admin panel features |
Future versions may include additional roles like Editor, Viewer, or Content Manager with granular permissions.
Creating Admin Users
New administrators are created through the database seeding process during initial setup.Initial Admin Setup
During installation, a default admin account is created:Managing Users
Accessing User Management
A dedicated user management interface is under development. Currently at
/admin/users, which shows a placeholder page.- Database Tools: Using Drizzle Studio or direct database access
- Command Line: Using database seeding scripts
Using Drizzle Studio
Drizzle Studio provides a GUI for database management:- Adding Users
- Editing Users
- Removing Users
To add a new administrator:
- Open the
usertable in Drizzle Studio - Click “Add Row” or similar option
- Enter user details:
name: Administrator’s full nameemail: Login email (must be unique)emailVerified: Set to current timestamp
- Save the record
- Set password using Better Auth’s password hashing
Password Management
Password Requirements
Better Auth enforces secure password standards:- Minimum length requirements
- Secure bcrypt hashing
- Protection against common passwords
Changing Your Password
Password Recovery Process
The password recovery system works as follows:Receive Email
A password reset email is sent via Gmail (configured in environment variables):
- Contains secure reset token
- Link valid for limited time
- Sent to registered email address
Reset Password
Click the link in the email to access
/restablecer-password:- Enter new password
- Confirm password
- Submit to update
Email Configuration
Password recovery requires Gmail SMTP configuration.Setting Up Gmail for Password Reset
Generate App Password
Create an app-specific password:
- Go to Google App Passwords
- Select “Mail” and your device
- Generate password
- Copy the 16-character password
Session Management
How Sessions Work
Better Auth manages user sessions:- Sessions stored in database
- Secure session tokens in cookies
- Automatic expiration after inactivity
- Protection against CSRF attacks
Session Configuration
Session settings are configured insrc/lib/server/auth.js:
Logging Out
Users can log out from the admin panel:- Click the logout icon in the sidebar user profile
- Session is terminated server-side
- Redirected to login page
Security Best Practices
- Password Security
- Access Control
- Environment Security
- Use strong, unique passwords for each admin
- Change default passwords immediately
- Enable 2FA on Gmail accounts used for recovery
- Rotate passwords periodically (every 90 days)
- Never share admin credentials
Route Protection
Admin routes are protected by authentication middleware:Protected Routes
All routes under/admin/* require authentication:
/admin- Main dashboard/admin/users- User management (under development)- All admin panel sections
Authentication Flow
Layout Server Protection
The filesrc/routes/admin/+layout.server.js enforces authentication:
Troubleshooting
Common Issues
Can't access admin panel
Can't access admin panel
Symptoms: Redirected to login even after entering credentialsSolutions:
- Clear browser cookies
- Check if user exists in database
- Verify password is correct
- Check Better Auth configuration
- Review server logs for errors
Password reset email not received
Password reset email not received
Symptoms: No email arrives after requesting password resetSolutions:
- Check spam/junk folder
- Verify
GMAIL_USERandGMAIL_APP_PASSWORDin.env - Confirm Gmail app password is correct
- Check server logs for email sending errors
- Verify email address is correct in database
Session expires too quickly
Session expires too quickly
Symptoms: Logged out frequently during useSolutions:
- Check Better Auth session configuration
- Review session timeout settings
- Ensure cookies are enabled in browser
- Check for clock synchronization issues
Future User Management Features
Planned enhancements include:- User Management UI: Dedicated interface for adding/editing users
- Role-Based Access Control: Multiple permission levels
- Activity Logging: Track admin actions and changes
- Two-Factor Authentication: Additional security layer
- User Invitations: Email-based invite system
Next Steps
Admin Panel Usage
Learn to navigate the admin interface
Deployment
Deploy your site securely to production
