{"record":{"id":"b0e09a0be719983c","repo":"hcengineering/platform","slug":"accounts-url-or-token-is-not-defined-b0e09a","errorCode":null,"errorMessage":"Accounts URL or token is not defined","messagePattern":"Accounts URL or token is not defined","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/setting-resources/src/utils.ts","lineNumber":120,"sourceCode":"\n  const employee = get(employeeByPersonIdStore).get(value.modifiedBy)\n  if (employee != null && client.getHierarchy().hasMixin(employee, contact.mixin.Employee)) {\n    return client.getHierarchy().as(employee, contact.mixin.Employee)?.position ?? undefined\n  }\n}\n\nexport function getAccountClient (): AccountClient {\n  const accountsUrl = getMetadata(login.metadata.AccountsUrl)\n  const token = getMetadata(presentation.metadata.Token)\n\n  return getAccountClientRaw(accountsUrl, token)\n}\n\nexport async function getIntegrationClient (kind: IntegrationKind): Promise<IntegrationClient> {\n  const accountsUrl = getMetadata(login.metadata.AccountsUrl)\n  const token = getMetadata(presentation.metadata.Token)\n  if (accountsUrl === undefined || token === undefined) {\n    throw new Error('Accounts URL or token is not defined')\n  }\n  return getIntegrationClientRaw(accountsUrl, token, kind, 'settings')\n}\n","sourceCodeStart":102,"sourceCodeEnd":124,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/setting-resources/src/utils.ts#L102-L124","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the user is logged in and the platform (login + presentation) metadata is fully initialized before calling `getIntegrationClient`.","Verify the server deployment sets the accounts URL so `login.metadata.AccountsUrl` is populated (check `ACCOUNTS_URL`/transactor config).","Re-authenticate if the session expired, then reload so the token metadata is restored.","Gate the call site on metadata availability: check both values (or catch this error) and defer/retry the integration setup.","In tests/dev harnesses, mock `getMetadata` to return a test URL and token."],"exampleFix":"// before\nconst client = await getIntegrationClient('github')\n\n// after\nconst accountsUrl = getMetadata(login.metadata.AccountsUrl)\nconst token = getMetadata(presentation.metadata.Token)\nif (accountsUrl === undefined || token === undefined) {\n  await waitForPlatformReady() // or redirect to login\n}\nconst client = await getIntegrationClient('github')","handlingStrategy":"validation","validationCode":"import { getMetadata } from '@hcengineering/presentation'\nimport { login } from '@hcengineering/login'\nconst accountsUrl = getMetadata(login.metadata.AccountsUrl)\nconst token = getMetadata(presentation.metadata.Token)\nif (accountsUrl === undefined || token === undefined) {\n  throw new Error('Platform metadata not ready: accounts URL or token missing')\n}","typeGuard":"function hasPlatformMetadata(): boolean {\n  return getMetadata(login.metadata.AccountsUrl) !== undefined &&\n         getMetadata(presentation.metadata.Token) !== undefined\n}","tryCatchPattern":"try {\n  const client = await getIntegrationClient(kind)\n  // use client...\n} catch (err) {\n  if (err instanceof Error && err.message === 'Accounts URL or token is not defined') {\n    // defer integration setup until login completes, or surface a re-login prompt\n  } else throw err\n}","preventionTips":["Initialize integrations only after login completes and platform metadata is loaded.","Verify the deployment configures the accounts URL server-side (`ACCOUNTS_URL`).","Handle session expiry by redirecting to login rather than calling integration APIs.","In tests/dev harnesses, stub `getMetadata` with valid URL and token values."],"tags":["configuration","authentication","missing-metadata","integration"],"backgroundTag":"missing-env-var","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}