hcengineering/platform · error

Accounts URL or token is not defined

Error message

Accounts URL or token is not defined

What it means

`getIntegrationClient(kind)` builds an integration API client using the platform's accounts URL and the current user's token, both read from application metadata (`login.metadata.AccountsUrl` and `presentation.metadata.Token`). If either is `undefined`, the client cannot authenticate or address the accounts service, so the function throws immediately instead of issuing a doomed request. This typically means the code is running outside a properly initialized Huly platform session.

Source

Thrown at plugins/setting-resources/src/utils.ts:120

  const employee = get(employeeByPersonIdStore).get(value.modifiedBy)
  if (employee != null && client.getHierarchy().hasMixin(employee, contact.mixin.Employee)) {
    return client.getHierarchy().as(employee, contact.mixin.Employee)?.position ?? undefined
  }
}

export function getAccountClient (): AccountClient {
  const accountsUrl = getMetadata(login.metadata.AccountsUrl)
  const token = getMetadata(presentation.metadata.Token)

  return getAccountClientRaw(accountsUrl, token)
}

export async function getIntegrationClient (kind: IntegrationKind): Promise<IntegrationClient> {
  const accountsUrl = getMetadata(login.metadata.AccountsUrl)
  const token = getMetadata(presentation.metadata.Token)
  if (accountsUrl === undefined || token === undefined) {
    throw new Error('Accounts URL or token is not defined')
  }
  return getIntegrationClientRaw(accountsUrl, token, kind, 'settings')
}

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Ensure the user is logged in and the platform (login + presentation) metadata is fully initialized before calling `getIntegrationClient`.
  2. Verify the server deployment sets the accounts URL so `login.metadata.AccountsUrl` is populated (check `ACCOUNTS_URL`/transactor config).
  3. Re-authenticate if the session expired, then reload so the token metadata is restored.
  4. Gate the call site on metadata availability: check both values (or catch this error) and defer/retry the integration setup.
  5. In tests/dev harnesses, mock `getMetadata` to return a test URL and token.

Example fix

// before
const client = await getIntegrationClient('github')

// after
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
const token = getMetadata(presentation.metadata.Token)
if (accountsUrl === undefined || token === undefined) {
  await waitForPlatformReady() // or redirect to login
}
const client = await getIntegrationClient('github')
Defensive patterns

Strategy: validation

Validate before calling

import { getMetadata } from '@hcengineering/presentation'
import { login } from '@hcengineering/login'
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
const token = getMetadata(presentation.metadata.Token)
if (accountsUrl === undefined || token === undefined) {
  throw new Error('Platform metadata not ready: accounts URL or token missing')
}

Type guard

function hasPlatformMetadata(): boolean {
  return getMetadata(login.metadata.AccountsUrl) !== undefined &&
         getMetadata(presentation.metadata.Token) !== undefined
}

Try / catch

try {
  const client = await getIntegrationClient(kind)
  // use client...
} catch (err) {
  if (err instanceof Error && err.message === 'Accounts URL or token is not defined') {
    // defer integration setup until login completes, or surface a re-login prompt
  } else throw err
}

Prevention

When it happens

Trigger: Calling `getIntegrationClient` before the login/presentation metadata has been loaded into the platform context; running the settings UI in an environment where the server did not configure `AccountsUrl`; an unauthenticated/expired session where the token metadata is absent; embedding the component in a standalone dev harness without platform bootstrap.

Common situations: Development/preview builds missing the `ACCOUNTS_URL` server config; a stale page where the session token lapsed and metadata was cleared; invoking the function in unit tests without mocking platform metadata; plugin code executing before `login` metadata initializes.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/b0e09a0be719983c. Report an issue: GitHub.