Constructors

Methods

  • Authenticates with the UniFi controller

    Performs login with the configured credentials and establishes a session. Prevents multiple concurrent login attempts and handles authentication errors.

    Returns Promise<void>

    Throws

    When login credentials are invalid or login fails

    Throws

    When unable to connect to the controller

    Example

    try {
    await sessionManager.login();
    console.log('Login successful');
    } catch (error) {
    if (error instanceof AuthenticationError) {
    console.error('Invalid credentials');
    }
    }
  • Logs out from the UniFi controller

    Terminates the current session and clears all authentication state. Always succeeds locally even if the server request fails.

    Returns Promise<void>

    Example

    await sessionManager.logout();
    console.log('Logged out successfully');
  • 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.

    Returns Promise<void>

    Throws

    When authentication fails

    Throws

    When session has expired and refresh fails

  • Checks if currently authenticated

    Returns boolean

    true if session is active, false otherwise

  • Gets the authenticated username

    Returns undefined | string

    Username if authenticated, undefined otherwise

  • Gets the configured site name

    Returns string

    Site name (defaults to 'default')

  • 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.

    Type Parameters

    • T

      Return type of the API call

    Parameters

    • apiCall: (() => Promise<T>)

      Function that makes the API call

        • (): Promise<T>
        • Returns Promise<T>

    Returns Promise<T>

    Promise resolving to the API call result

    Throws

    When authentication fails

    Example

    const devices = await sessionManager.withAuth(async () => {
    return httpClient.get('/api/s/default/stat/device');
    });