HTTP client instance for making requests
UniFi client configuration containing credentials and settings
When configuration is invalid
Authenticates with the UniFi controller
Performs login with the configured credentials and establishes a session. Prevents multiple concurrent login attempts and handles authentication errors.
When login credentials are invalid or login fails
When unable to connect to the controller
try {
await sessionManager.login();
console.log('Login successful');
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid credentials');
}
}
Ensures the client is authenticated
Checks current authentication status and performs login or session refresh as needed. This method is called automatically by API methods.
When authentication fails
When session has expired and refresh fails
Gets current session information
Copy of current session information including authentication status, login time, last activity, username, and site
Wraps an API call with automatic authentication
Ensures authentication before executing the API call and handles re-authentication if the session expires during the call.
Promise resolving to the API call result
When authentication fails
const devices = await sessionManager.withAuth(async () => {
return httpClient.get('/api/s/default/stat/device');
});
Creates a new session manager instance