Overview
CONFOR implements a comprehensive authentication system that supports multiple authentication providers, role-based access control (RBAC), and organization-scoped permissions. The system ensures secure access to forestry data while providing flexible user management capabilities.Key Features
Multi-Provider Auth
Support for local authentication, Google, GitHub, and Microsoft OAuth providers
Role-Based Access
Flexible RBAC system with custom roles and granular permissions
Organization Scoping
Users are scoped to organizations with isolated data access
Session Management
Secure session handling with refresh tokens and device tracking
Authentication Providers
CONFOR supports multiple authentication methods:prisma/schema.prisma
Local Authentication
Users can register with email and password using the registration endpoint:src/app/api/auth/register/route.ts
OAuth Providers
External authentication through:- Google: Social login via Google OAuth 2.0
- GitHub: Developer authentication
- Microsoft: Enterprise single sign-on
User Status Lifecycle
Users progress through different status states:prisma/schema.prisma
Registration Workflow
- User Registration: User submits registration form with email, password, and profile details
- Organization Assignment: User is assigned to a default or specified organization
- Pending Verification: Account status set to
PENDING_VERIFICATION - Admin Approval: Organization admin activates the user
- Active Status: User can access the system
New users require admin approval before accessing the system. This ensures controlled access to sensitive forestry data.
Role-Based Access Control
Permission Model
Permissions are organized by module and action:prisma/schema.prisma
System Roles
SUPER_ADMIN
SUPER_ADMIN
Full system access across all organizations. Can manage organizations, system configurations, and global settings.
ADMIN
ADMIN
Organization-scoped administrator. Can manage users, roles, and data within their organization.
USER
USER
Standard user with read and write access to forestry data based on assigned permissions.
Permission Enforcement
API routes enforce permissions using helper functions:src/app/api/forest/patrimony/route.ts
Organization Scoping
All users belong to an organization, and data access is scoped accordingly:src/app/api/organizations/route.ts
Organization Properties
- Name & Slug: Unique identifier for the organization
- Country Association: Geographic location
- Active Status: Control organization access
- Settings: Custom configuration (including RIF/tax ID)
Session Management
Session Features
Session Data Structure
prisma/schema.prisma
Password Management
Password Requirements
Passwords must meet security criteria defined in validation schemas:src/validations/auth.schema.ts
Password Reset Flow
- User requests password reset via
/api/auth/forgot-password - System generates secure token stored in
PasswordResetTokentable - Token sent to user’s email (expires after configured time)
- User submits new password with token via
/api/auth/reset-password - Token validated and password updated
Security Features
Password Hashing
Secure password storage using industry-standard hashing algorithms
Failed Login Tracking
Automatic account locking after multiple failed attempts
MFA Support
Optional multi-factor authentication with backup codes
Audit Logging
All authentication events logged for security monitoring
Account Locking
prisma/schema.prisma
Login Validation
Before authentication, the system validates user eligibility:src/app/api/auth/login-validation/route.ts
Audit Trail
All authentication events are logged:src/app/api/auth/register/route.ts
Audited Actions
LOGIN: Successful user loginLOGOUT: User logoutLOGIN_FAILED: Failed login attemptPASSWORD_RESET: Password reset requestPERMISSION_CHANGE: Role or permission modification
Best Practices
Related Documentation
- Organizations - Organization management and configuration
- API Reference - Authentication API endpoints