{"record":{"id":"d256b26bec69fee2","repo":"hcengineering/platform","slug":"accounts-url-or-token-is-not-defined-d256b2","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/huly-mail-resources/src/utils.ts","lineNumber":29,"sourceCode":"//\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\nimport { getMetadata } from '@hcengineering/platform'\nimport presentation from '@hcengineering/presentation'\nimport login from '@hcengineering/login'\nimport { hulyMailIntegrationKind } from '@hcengineering/huly-mail'\nimport {\n  getIntegrationClient as getIntegrationClientRaw,\n  type IntegrationClient\n} from '@hcengineering/integration-client'\nimport { getClient as getAccountClientRaw, type AccountClient } from '@hcengineering/account-client'\n\nexport async function getIntegrationClient (): 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, hulyMailIntegrationKind, 'huly-mail')\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","sourceCodeStart":11,"sourceCodeEnd":40,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/huly-mail-resources/src/utils.ts#L11-L40","documentation":"getIntegrationClient in huly-mail-resources mirrors the gmail integration: it needs the AccountsUrl and the session token from metadata to construct the Huly Mail integration client via getIntegrationClientRaw. Missing either metadata value triggers 'Accounts URL or token is not defined'.","triggerScenarios":"Invoking integrationClient before login metadata exists (early startup), AccountsUrl not configured for the deployment, or unauthenticated session where presentation.metadata.Token is undefined.","commonSituations":"Huly Mail integration initialized before sign-in; accounts service URL omitted from platform configuration; session expired/cleared token while the integration retries; unit tests that don't set login/presentation metadata.","solutions":["Set login.metadata.AccountsUrl in platform configuration.","Ensure authentication completes and the token is stored in metadata before creating the integration client.","Initialize the integration lazily after the auth-ready/login event rather than at module load.","In tests, seed metadata with a test accounts URL and token."],"exampleFix":"// before\nconst accountsUrl = getMetadata(login.metadata.AccountsUrl)\nconst token = getMetadata(presentation.metadata.Token)\nif (accountsUrl === undefined || token === undefined) {\n  throw new Error('Accounts URL or token is not defined')\n}\n// after\nconst accountsUrl = getMetadata(login.metadata.AccountsUrl)\nconst token = getMetadata(presentation.metadata.Token)\nif (accountsUrl === undefined || token === undefined) {\n  throw new Error('Accounts URL or token is not defined: check deployment config and login state')\n}","handlingStrategy":"validation","validationCode":"const accountsUrl = getMetadata(login.metadata.AccountsUrl)\nconst token = getMetadata(presentation.metadata.Token)\nif (accountsUrl === undefined || token === undefined) {\n  throw new Error('Huly Mail integration needs AccountsUrl config and a valid session token')\n}\nconst client = await integrationClient()","typeGuard":"function hasAuthMetadata (m: { accountsUrl: string | undefined, token: string | undefined }): m is { accountsUrl: string, token: string } {\n  return m.accountsUrl !== undefined && m.token !== undefined\n}","tryCatchPattern":"try {\n  const client = await integrationClient()\n  // use client\n} catch (err) {\n  if (err instanceof Error && err.message === 'Accounts URL or token is not defined') {\n    console.error('Huly Mail integration misconfigured: verify accounts URL and login token')\n    return\n  }\n  throw err\n}","preventionTips":["Verify deployment config includes the accounts service URL.","Defer integration client creation until after the auth-ready event.","Reuse a shared authentication metadata guard across all resource integrations.","Seed metadata in test harnesses before integration tests run."],"tags":["authentication","configuration","metadata","huly-platform"],"backgroundTag":"missing-env-var","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}