Skip to main content

Authentication

The authentication module provides methods for user login, logout, and session management.

login

Authenticate a user with email and password.
db.auth.login(email: string, pass: string): User | null
email
string
required
User’s email address
pass
string
required
User’s password
User
object | null
Returns User object if authentication succeeds, null otherwise
Example:
const user = db.auth.login('[email protected]', 'admin123');
if (user) {
  console.log('Logged in:', user.name);
}

logout

End the current user session.
db.auth.logout(): void
Removes the session from localStorage. Example:
db.auth.logout();

getCurrentUser

Retrieve the currently authenticated user.
db.auth.getCurrentUser(): User | null
User
object | null
Returns the current user’s session data, or null if not logged in
Example:
const currentUser = db.auth.getCurrentUser();
if (currentUser) {
  console.log('Current user:', currentUser.email);
}

getAllUsers

Get all registered users in the system.
db.auth.getAllUsers(): User[]
users
User[]
Array of all users
Example:
const users = db.auth.getAllUsers();
console.log('Total users:', users.length);

updateCurrentUser

Update the current user’s profile information.
db.auth.updateCurrentUser(updates: Partial<User>): User | null
updates
Partial<User>
required
Object containing the fields to update
User
object | null
Returns the updated user object, or null if no session exists
Example:
const updated = db.auth.updateCurrentUser({
  name: 'New Name',
  avatarUrl: 'https://example.com/avatar.jpg',
  interests: ['Meditación', 'Yoga']
});

User Types

User

interface User {
  id: string;
  name: string;
  email: string;
  role: UserRole;
  avatarUrl: string;
  tenantId: string;
  interests: string[];
  joinedDate: string;
  coverUrl?: string;
  phone?: string;
  city?: string;
}

UserRole

enum UserRole {
  SUPER_ADMIN = 'SUPER_ADMIN',
  ADMIN = 'ADMIN',
  EDITOR = 'EDITOR',
  MEMBER = 'MEMBER',
  GUEST = 'GUEST'
}

User History

Track user activities and engagement.

getHistory

Retrieve the activity history for the current user.
db.user.getHistory(): UserActivity[]
activities
UserActivity[]
Array of user activities
Example:
const history = db.user.getHistory();
console.log('Recent activities:', history);

addHistory

Log a new user activity.
db.user.addHistory(activity: UserActivity): void
activity
UserActivity
required
The activity to record
Example:
db.user.addHistory({
  id: 'act_123',
  type: 'Event',
  title: 'Meditation Workshop',
  date: '2024-03-15',
  status: 'Registered'
});

getPreferences

Get user preferences (theme, notifications, etc.).
db.user.getPreferences(): any
preferences
object
User preference settings
Example:
const prefs = db.user.getPreferences();
console.log('Theme:', prefs.theme);
console.log('Notifications:', prefs.notifications);

Build docs developers (and LLMs) love