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
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.
Removes the session from localStorage.
Example:
getCurrentUser
Retrieve the currently authenticated user.
db.auth.getCurrentUser(): User | 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[]
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
Object containing the fields to update
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[]
Example:
const history = db.user.getHistory();
console.log('Recent activities:', history);
addHistory
Log a new user activity.
db.user.addHistory(activity: UserActivity): void
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
Example:
const prefs = db.user.getPreferences();
console.log('Theme:', prefs.theme);
console.log('Notifications:', prefs.notifications);