Overview
The User model is the central data structure representing MentraOS users. It stores authentication data, preferences, installed apps, and system settings.Location
packages/cloud/src/models/user.model.ts
Schema Structure
Core Fields
MentraOS Settings
System-wide user preferences:Location Data
Installed Apps
Instance Methods
App Management
installApp(packageName: string)
Installs an app for the user.
uninstallApp(packageName: string)
Removes an app from user’s installed apps.
isAppInstalled(packageName: string)
Checks if an app is installed.
Running Apps
addRunningApp(appName: string)
Marks an app as currently running.
removeRunningApp(appName: string)
Removes app from running list.
isAppRunning(appName: string)
Checks if an app is currently active.
Settings Management
updateAppSettings(appName: string, settings: Array)
Updates user’s settings for a specific app.
getAppSettings(appName: string)
Retrieves user’s settings for an app.
Location
setLocation(location: Location)
Updates user’s location.
Static Methods
findOrCreateUser(email: string)
Finds existing user or creates new one.
findByEmail(email: string)
Finds user by email address.
Indexes
- email: Unique index for authentication
- organizations: For organization queries
- installedApps.packageName: For app usage analytics
Relationships
Organizations
Users can belong to multiple organizations:- Personal organization (default)
- Company organizations
- Shared app organizations
Apps
Two types of app relationships:- Installed Apps: Apps the user has added
- Running Apps: Apps currently active in session
Gallery Photos
Referenced by GalleryPhoto model using userId.Security Features
Data Sanitization
All user input is sanitized using MongoSanitizer:- Prevents NoSQL injection
- Validates data types
- Strips dangerous operators
Field Protection
Sensitive fields are never exposed:- Password hashes
- API tokens
- Internal IDs
Migration Support
The model supports gradual migration from legacy fields:Legacy Fields (Deprecated)
Default Values
MentraOS Settings Defaults
Best Practices
- Always use
findOrCreateUserfor user creation - Sanitize all inputs before database operations
- Use lean() for read-only operations
- Update arrays atomically using MongoDB operators
- Log all setting changes for audit trail