Overview
SuperTokens Core provides a flexible metadata system for storing custom user attributes beyond authentication data. Store any JSON data associated with users including preferences, profile information, app-specific settings, and more.Features
JSON Storage
Store any valid JSON structure
Shallow Merge
Updates merge with existing data
Bulk Operations
Get metadata for multiple users
Storage Structure
Metadata is stored as a JSON object per user:Metadata is stored per app, not per tenant. All tenants in an app share the same user metadata.
Creating/Updating Metadata
From io/supertokens/usermetadata/UserMetadata.java:53-80:Example: Update User Metadata
Shallow Merge Behavior
Updates use shallow merge - top-level keys are merged:Retrieving Metadata
From io/supertokens/usermetadata/UserMetadata.java:124-136:Example: Get User Metadata
Bulk Metadata Retrieval
From io/supertokens/usermetadata/UserMetadata.java:138-166: Get metadata for multiple users in a single query:Example: Bulk Retrieval
Bulk retrieval is optimized for performance and should be used when fetching metadata for lists of users.
Bulk Metadata Update
From io/supertokens/usermetadata/UserMetadata.java:82-116:Example: Bulk Update
Deleting Metadata
From io/supertokens/usermetadata/UserMetadata.java:174-177:Example: Delete Metadata
To delete specific fields, retrieve the metadata, remove the fields, and update with the modified object.
Common Use Cases
User Preferences
User Profile
Subscription Management
Onboarding Progress
Feature Flags
Metadata in Bulk Import
Metadata can be imported during bulk user import:Best Practices
Structure Data
Organize metadata into logical top-level objects
Avoid Deep Nesting
Keep structure flat due to shallow merge behavior
Use Consistent Keys
Standardize metadata keys across your application
Validate Data
Validate metadata before storage
Handle Nulls
Check for null before accessing nested properties
Use Bulk Operations
Prefer bulk methods when working with multiple users
Data Size Considerations
- Recommended: User preferences, profile info, settings
- Not Recommended: Large binary data, extensive logs, file contents
- Store references (URLs, IDs) in metadata
- Keep actual data in your application database or object storage