Use this file to discover all available pages before exploring further.
The accounts-base package implements Meteor’s foundational user account system, providing the core infrastructure for authentication and user management.
// Get current user (reactive)const user = Meteor.user();// Get current user ID (reactive)const userId = Meteor.userId();// Check login status (reactive)const isLoggedIn = !!Meteor.userId();
These methods are reactive and will trigger re-runs when the login state changes.
// Check if login methods are readyconst ready = Meteor.loggingIn();// Wait for user data to loadTracker.autorun(() => { if (!Meteor.userId() && !Meteor.loggingIn()) { console.log('User is logged out'); }});
// Validate new user creationAccounts.validateNewUser((user) => { // Check email domain if (user.emails && user.emails[0]) { const email = user.emails[0].address; if (!email.endsWith('@company.com')) { throw new Meteor.Error('invalid-email', 'Only company emails allowed'); } } return true;});// Validate login attemptsAccounts.validateLoginAttempt((attempt) => { // Reject if user is not active if (attempt.user && !attempt.user.active) { throw new Meteor.Error('user-inactive', 'Account is inactive'); } return true;});
// Run code on user loginAccounts.onLogin((loginInfo) => { console.log('User logged in:', loginInfo.user._id); console.log('Connection:', loginInfo.connection.id); // Update last login time Meteor.users.updateAsync(loginInfo.user._id, { $set: { lastLogin: new Date() } });});// Run code on user logoutAccounts.onLogout((logoutInfo) => { console.log('User logged out:', logoutInfo.user._id);});// Run code on failed loginAccounts.onLoginFailure((failureInfo) => { console.log('Login failed:', failureInfo.error.reason);});