Skip to main content

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
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)

These are being migrated to the Organization model.

Default Values

MentraOS Settings Defaults

Best Practices

  1. Always use findOrCreateUser for user creation
  2. Sanitize all inputs before database operations
  3. Use lean() for read-only operations
  4. Update arrays atomically using MongoDB operators
  5. Log all setting changes for audit trail

Example Usage