hcengineering/platform · error
Accounts URL or token is not defined
Error message
Accounts URL or token is not defined
What it means
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'.
Source
Thrown at plugins/huly-mail-resources/src/utils.ts:29
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import { getMetadata } from '@hcengineering/platform'
import presentation from '@hcengineering/presentation'
import login from '@hcengineering/login'
import { hulyMailIntegrationKind } from '@hcengineering/huly-mail'
import {
getIntegrationClient as getIntegrationClientRaw,
type IntegrationClient
} from '@hcengineering/integration-client'
import { getClient as getAccountClientRaw, type AccountClient } from '@hcengineering/account-client'
export async function getIntegrationClient (): 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, hulyMailIntegrationKind, 'huly-mail')
}
export function getAccountClient (): AccountClient {
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
const token = getMetadata(presentation.metadata.Token)
return getAccountClientRaw(accountsUrl, token)
}
View on GitHub (pinned to 63e28dc964)
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.
Example fix
// before
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')
}
// after
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: check deployment config and login state')
} Defensive patterns
Strategy: validation
Validate before calling
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
const token = getMetadata(presentation.metadata.Token)
if (accountsUrl === undefined || token === undefined) {
throw new Error('Huly Mail integration needs AccountsUrl config and a valid session token')
}
const client = await integrationClient() Type guard
function hasAuthMetadata (m: { accountsUrl: string | undefined, token: string | undefined }): m is { accountsUrl: string, token: string } {
return m.accountsUrl !== undefined && m.token !== undefined
} Try / catch
try {
const client = await integrationClient()
// use client
} catch (err) {
if (err instanceof Error && err.message === 'Accounts URL or token is not defined') {
console.error('Huly Mail integration misconfigured: verify accounts URL and login token')
return
}
throw err
} Prevention
- 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.
When it happens
Trigger: Invoking integrationClient before login metadata exists (early startup), AccountsUrl not configured for the deployment, or unauthenticated session where presentation.metadata.Token is undefined.
Common situations: 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.
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
- Accounts URL or token is not defined
- Workspace ${options.workspace} not found
- Token not specified
- Authentication token not specified
- WorkspaceUuid is not defined
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/d256b26bec69fee2.
Report an issue: GitHub.