{"record":{"id":"c4f066d859aaa756","repo":"hcengineering/platform","slug":"platform-status-accountnotfound","errorCode":"platform.status.AccountNotFound","errorMessage":"AccountNotFound","messagePattern":"AccountNotFound","errorType":"exception","errorClass":"PlatformError","httpStatus":null,"severity":"error","filePath":"server/account/src/operations.ts","lineNumber":766,"sourceCode":"  params: {\n    role: AccountRole\n    firstName?: string\n    lastName?: string\n    extra?: string\n    navigateUrl?: string\n    spaces?: string[]\n\n    notBefore?: number\n    expiration?: number\n    personalized?: boolean\n  }\n): Promise<string> {\n  const { role, firstName, lastName, navigateUrl, spaces, notBefore, expiration, personalized = true } = params\n  const { account, workspace: workspaceUuid, extra } = decodeTokenVerbose(ctx, token)\n\n  const currentAccount = await db.account.findOne({ uuid: account })\n  if (currentAccount == null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, { account }))\n  }\n\n  if (workspaceUuid == null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))\n  }\n\n  const workspace = await db.workspace.findOne({ uuid: workspaceUuid })\n  if (workspace == null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspaceUuid }))\n  }\n\n  let extraObj: Record<string, string> | undefined\n\n  if (params.extra != null) {\n    try {\n      extraObj = JSON.parse(params.extra)\n    } catch (e) {\n      ctx.error(\"Invalid extra parameter, couldn't parse JSON\", { extra: params.extra })","sourceCodeStart":748,"sourceCodeEnd":784,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/operations.ts#L748-L784","documentation":"createAccessLink decodes an access token and looks up the account UUID it embeds via db.account.findOne. If no account row matches that UUID, the platform throws AccountNotFound. This means the token references an account that no longer exists (or never existed) in the database.","triggerScenarios":"Calling createAccessLink with a token whose embedded `account` UUID is absent from db.account — e.g. the account was deleted after the token was issued, the token was minted for a different/staging database, or the token is forged/corrupted.","commonSituations":"Pointing a client at a fresh or restored database while reusing old tokens; account cleanup jobs deleting accounts with live tokens; copying tokens between environments (dev/prod); typos when manually crafting tokens in tests.","solutions":["Re-authenticate so the user gets a token minted against the current database.","Verify the token was issued for the same environment/database you are calling (check transactor URL and DB name).","Confirm the account row still exists: query db.account.findOne({ uuid: <account from token> }).","If accounts are being deleted, invalidate/revoke outstanding tokens on deletion to avoid stale-token calls."],"exampleFix":"// before: reusing an old token after DB reset\nconst link = await client.createAccessLink(token, params)\n// after: re-login to obtain a token for the current DB\nconst token = await login(email, password)\nconst link = await client.createAccessLink(token, params)","handlingStrategy":"try-catch","validationCode":"const payload = decodeJwt(token)\nif (payload?.account == null) throw new Error('token missing account claim')","typeGuard":"function hasAccountClaim(t: unknown): t is { account: string } {\n  return typeof t === 'object' && t !== null && typeof (t as any).account === 'string'\n}","tryCatchPattern":"try {\n  const link = await createAccessLink(token, params)\n} catch (err) {\n  if (isPlatformError(err, platform.status.AccountNotFound)) {\n    await reauthenticate() // token references a deleted/foreign account\n  } else throw err\n}","preventionTips":["Re-login instead of reusing long-lived cached tokens after account changes.","Keep tokens environment-specific; never copy them between dev/staging/prod.","Invalidate tokens when deleting accounts."],"tags":["auth","account","token","not-found"],"backgroundTag":"account-not-found-for-token","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}