User Data Model
The platform uses MongoDB with Prisma for user data storage.User Schema
MongoDB ObjectId - unique user identifier
User’s email address (unique, used for authentication)
User’s full name
Profile image URL from OAuth provider
User’s location/city
Phone number
English level:
inicial, basico, intermedio, or avanzadoAccount status flag
Newsletter subscription:
si or noTotal number of completed classes
OAuth refresh token for Google services (admin only)
prisma/schema.prisma:111-128
Role System
The platform supports three user roles:Role Definitions
Standard user with access to student features
Administrator with full platform access
Moderator with elevated permissions (reserved for future use)
prisma/schema.prisma:16-20
Currently, admin status is determined by email match with
ADMIN_EMAIL environment variable rather than a database role field.User Authentication
Authentication is handled through NextAuth.js with OAuth providers.Supported Providers
- GitHub OAuth
- Google OAuth (with Calendar API access)
Authentication Flow
1. Sign In Callback
Implementation:src/auth.ts:35-53
2. JWT Token Handling
Implementation:src/auth.ts:55-85
Tokens include:
- User ID
- Access token for API calls
- Refresh token (admin only)
- 30-day expiration
3. Session Management
Implementation:src/auth.ts:87-104
Session data includes:
- User profile information
- JWT tokens
- Access and refresh tokens
- Token expiration times
Session Configuration
Session duration: 30 days (60 * 60 * 24 * 30 seconds)
Session update interval: 12 hours
User Creation
New users are created automatically during OAuth sign-in: Server Action:src/server-actions/actions.ts:26-42
User creation uses default values from schema for optional fields (localidad, telefono, nivel, etc.).
User Profile Management
Users can update their profile information after account creation.Retrieving User Data
Function:src/services/functions/index.ts:39-55
Updating User Data
Function:src/services/functions/index.ts:58-74
English Level Management
Users can set their English proficiency level:Level Options
| Level | Description |
|---|---|
inicial | Beginner/Initial level |
basico | Basic level |
intermedio | Intermediate level |
avanzado | Advanced level |
prisma/schema.prisma:28-33
Level selection affects:
- Activity difficulty recommendations
- Class matching
- Progress tracking
User Activity Tracking
Student progress is tracked through theUserActivity model:
UserActivity Schema
Reference to User ID
Reference to assigned Task
Reference to VirtualClass
User’s role in class:
anfitrion (host) or participante (participant)Whether the activity has been completed
prisma/schema.prisma:168-180
Creating Activity Records
When a user joins or creates a class:src/services/functions/index.ts:229-237
Admin User Features
Administrators have additional capabilities:Refresh Token Storage
Only admin users store Google OAuth refresh tokens:src/auth.ts:73-76
This enables:
- Persistent Google Calendar access
- Creating events on behalf of the platform
- Accessing Calendar API without repeated authorization
Refresh Token Database Storage
Function:src/services/functions/index.ts:9-22
Total Classes Counter
ThetotalClasses field tracks completed classes per user:
Incrementing Class Count
After activity upload for a class:src/app/(dashboard)/admin/actividad/[classId]/actions.ts:98-110
This counter:
- Increments when admin uploads activity for a class
- Tracks all participants in the class
- Provides student progress metrics
User Relationships
Users are related to multiple entities:One-to-Many Relationships
- UserActivity[] - All user’s class activities
- PaymentMercadoPago[] - User’s payment records
- SupportTicket[] - User’s support tickets
Through Virtual Classes
- Classes hosted (via
bookedById) - Classes attended (via
participantsIdsarray)
Security Considerations
Admin Email Protection
Admin status should never be stored in client-accessible state:Session Security
- Sessions expire after 30 days
- JWT tokens are signed and validated
- Refresh tokens are only stored for admin users
- OAuth providers handle password management
Related Resources
Authentication Setup
Configure OAuth providers and authentication
Class Management
Understand how users interact with classes