Authentication

The OLOClient provides built-in authentication methods for user login and appliance discovery.

Note: In the SDK Playground, authentication is automatic - you don't need these methods unless connecting to additional appliances.

authenticate(username, password)

Authenticate user with username and password.

Parameters:

  • username (string) - Username or email
  • password (string) - Password

Returns: Promise<Object> - Authentication result with token

JS
// Create a new client instance for authentication const oloClient = new OLOClient({ apiUrl: 'https://app.olo-robotics.com' }); const result = await oloClient.authenticate('[email protected]', 'mypassword'); console.log('Auth token:', result.token);

getUserRobots()

Get list of appliances for the authenticated user. Must call authenticate() first.

Returns: Promise<Array> - Array of appliance objects

JS
// Must authenticate first await oloClient.authenticate('[email protected]', 'mypassword'); const appliances = await oloClient.getUserRobots(); console.log('Available appliances:', appliances);

getAuthToken()

Get stored authentication token.

Returns: string|null - Current auth token

JS
const token = oloClient.getAuthToken(); console.log('Current token:', token);

clearAuth()

Clear authentication token.

JS
oloClient.clearAuth();

Complete Authentication Flow

Full example showing authentication, robot discovery, and connection:

JS
// Complete authentication and connection example async function connectToRobot(username, password, serverUrl = 'https://app.olo-robotics.com') { try { // Step 1: Create client const oloClient = new OLOClient({ apiUrl: serverUrl }); // Step 2: Authenticate const authResult = await oloClient.authenticate(username, password); console.log('✅ Authentication successful'); // Step 3: Get available robots const robots = await oloClient.getUserRobots(); console.log(`Found ${robots.length} robots:`, robots); if (robots.length === 0) { throw new Error('No robots available for this user'); } // Step 4: Connect to first robot const robot = robots[0]; await oloClient.connect(robot.id, oloClient.getAuthToken()); console.log(`✅ Connected to robot: ${robot.name || robot.id}`); return { oloClient, robot }; } catch (error) { console.error('❌ Authentication/connection failed:', error); throw error; } } // Usage const { oloClient, robot } = await connectToRobot('[email protected]', 'mypassword');

Connecting to Multiple Appliances in SDK Playground

In the SDK Playground, you can connect to multiple appliances simultaneously by creating additional client instances. The pre-configured oloclient remains connected to your selected appliance, while you can create new clients for additional appliances.

Note: Each appliance connection can access multiple robots via ROS namespaces. This section is about connecting to different appliances, not different robots within the same ROS domain.

JS
// JavaScript version: Control multiple appliances const oloClient2 = new OLOClient({ apiUrl: 'https://app.olo-robotics.com' }); // Authenticate await oloClient2.authenticate('your-username', 'your-password'); const robots = await oloClient2.getUserRobots(); // Connect to second appliance await oloClient2.connect(robots[1].id, oloClient2.getAuthToken()); // Control both appliances await oloClient.core.sendVelocity('/cmd_vel', { linear: 0.5, angular: 0 }); await oloClient2.core.sendVelocity('/cmd_vel', { linear: -0.5, angular: 0 }); // Stop both await oloClient.core.stopRobot(); await oloClient2.core.stopRobot();