Preferences Storage
Store and manage user preferences with Nuvix's Account API and Teams API for individual and shared settings.
Store user settings that persist across sessions. Nuvix makes it simple to save themes, languages, notifications, and any custom preferences for both individual users and nx.teams.
User preferences
Store personal settings that follow users across devices. Perfect for themes, language choices, notification preferences, or any user-specific configuration.
Preferences are stored as JSON objects with a 64kB size limit. Store anything from simple boolean flags to complex nested configurations.
Update user preferences
Use the updatePrefs method to store user preferences as a JSON object.
import { Client } from '@nuvix/client';
const nx = new Client()
    .setEndpoint('https://api.nuvix.in/v1')
    .setProject('<PROJECT_ID>');
// Store user preferences
const prefs = await nx.account.updatePrefs({
    darkTheme: true,
    language: 'en',
    notifications: {
        email: true,
        push: false
    }
});
console.log('Preferences updated:', prefs);Get user preferences
Retrieve stored preferences with the getPrefs method.
import { Client } from '@nuvix/client';
const nx = new Client()
    .setEndpoint('https://api.nuvix.in/v1')
    .setProject('<PROJECT_ID>');
// Get current user preferences
const preferences = await nx.account.getPrefs();
console.log('User preferences:', preferences);
// Use preferences in your app
if (preferences.darkTheme) {
    document.body.classList.add('dark-mode');
}Team preferences
Team preferences let you store settings that apply to an entire team of users. Perfect for collaborative features like team-wide themes, notification preferences, or feature toggles.
All team members can access these shared preferences, making it easy to maintain consistency across your organization.
Update team preferences
Store team-wide settings using the updatePrefs method with a team ID.
import { Client } from '@nuvix/client';
const nx = new Client()
    .setEndpoint('https://api.nuvix.in/v1')
    .setProject('<PROJECT_ID>');
// Update team preferences
const teamPrefs = await nx.teams.updatePrefs('<TEAM_ID>', {
    theme: 'corporate',
    notificationsEnabled: true,
    defaultView: 'kanban',
    features: {
        analytics: true,
        exports: false
    }
});
console.log('Team preferences updated:', teamPrefs);Get team preferences
Fetch team preferences by passing a team ID to the getPrefs method.
import { Client } from '@nuvix/client';
const nx = new Client()
    .setEndpoint('https://api.nuvix.in/v1')
    .setProject('<PROJECT_ID>');
// Get team preferences
const teamPreferences = await nx.teams.getPrefs('<TEAM_ID>');
console.log('Team preferences:', teamPreferences);
// Apply team settings
if (teamPreferences.theme === 'corporate') {
    applyCorporateTheme();
}Team preferences are accessible to all team members. Use them for shared settings that should be consistent across your team.
Best practices
Keep preferences lightweight
Preferences are designed for small configuration data. For larger datasets, consider using Nuvix's database features instead.
Use consistent naming
Establish a naming convention for your preference keys. Consider using camelCase and grouping related settings:
{
    // Theme settings
    theme: 'dark',
    themeColor: 'blue',
    
    // Notification settings
    notificationsEmail: true,
    notificationsPush: false,
    
    // Feature flags
    features: {
        analytics: true,
        betaFeatures: false
    }
}Handle preferences gracefully
Always check if preferences exist before using them, and provide sensible defaults:
const loadUserPreferences = async () => {
    try {
        const prefs = await nx.account.getPrefs();
        
        // Apply preferences with fallbacks
        applyTheme(prefs.theme || 'light');
        setLanguage(prefs.language || 'en');
        configureNotifications(prefs.notifications || {});
        
    } catch (error) {
        // Use defaults if preferences fail to load
        console.log('Using default preferences');
        applyTheme('light');
        setLanguage('en');
    }
};Next: Multi-tenancy with Teams
Learn how to organize users into teams for collaborative features and shared resources.
How is this guide?
Last updated on