{"record":{"id":"4926f80d49e1aedc","repo":"hcengineering/platform","slug":"couldn-t-find-workspace-with-the-provided-token-4926f8","errorCode":null,"errorMessage":"Couldn't find workspace with the provided token","messagePattern":"Couldn't find workspace with the provided token","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"services/gmail/pod-gmail/src/main.ts","lineNumber":91,"sourceCode":"  const endpoints: Endpoint[] = [\n    {\n      endpoint: '/signin',\n      type: 'get',\n      handler: async (req, res) => {\n        try {\n          ctx.info('Signin request received')\n          const token = extractToken(req.headers)\n\n          if (token === undefined) {\n            res.status(401).send()\n            return\n          }\n          const redirectURL = req.query.redirectURL as string\n\n          const accountClient = getAccountClient(token)\n          const wsLoginInfo = await accountClient.getLoginInfoByToken()\n          if (!isWorkspaceLoginInfo(wsLoginInfo)) {\n            res.status(400).send({ err: \"Couldn't find workspace with the provided token\" })\n            return\n          }\n\n          const authProvider = gmailController.getAuthProvider()\n          const url = authProvider.getAuthUrl(redirectURL, {\n            workspace: wsLoginInfo.workspace,\n            userId: wsLoginInfo.account\n          })\n          res.send(url)\n        } catch (err) {\n          ctx.error('signin error', { message: (err as any).message })\n          res.status(500).send()\n        }\n      }\n    },\n    {\n      endpoint: '/signin/code',\n      type: 'get',","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/gmail/pod-gmail/src/main.ts#L73-L109","documentation":"The /signin endpoint looks up workspace login info from the account service using the provided token. If the token is valid but does not resolve to a workspace login (isWorkspaceLoginInfo returns false), the endpoint returns 400 with this fixed error string. It means the token identifies an account/user without a workspace context.","triggerScenarios":"accountClient.getLoginInfoByToken() returns a login info that fails the isWorkspaceLoginInfo guard — i.e. the token belongs to a user/session not tied to a workspace (e.g. a guest or service account token, or a token whose workspace was deleted).","commonSituations":"Using a personal/user token instead of a workspace-scoped token; the workspace was removed after the token was issued; calling the integration signin flow from a context with no workspace selected.","solutions":["Obtain a workspace-scoped token from the account service (ensure the user has selected/signed into a workspace).","Verify the workspace still exists and the user is a member of it.","Re-authenticate to get a fresh token if the workspace membership changed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before calling /signin, ensure the token is workspace-scoped:\nconst loginInfo = await accountClient.getLoginInfoByToken()\nif (!loginInfo || !('workspace' in loginInfo) || !loginInfo.workspace) {\n  // token does not map to a workspace; fix authentication context first\n}","typeGuard":"function isWorkspaceLoginInfo(info: any): info is { workspace: string; account: string } {\n  return info != null && typeof info === 'object' &&\n    typeof info.workspace === 'string' && info.workspace.length > 0 &&\n    typeof info.account === 'string'\n}","tryCatchPattern":"const res = await fetch(url + '/signin', { headers })\nif (res.status === 400) {\n  const body = await res.json()\n  if (body?.err === \"Couldn't find workspace with the provided token\") {\n    // prompt user to sign into a workspace and retry with a workspace-scoped token\n  }\n}","preventionTips":["Use workspace-scoped tokens, not bare user tokens, for integration signin.","Verify the user still belongs to the workspace before starting the integration flow.","Handle deleted/reassigned workspaces by forcing re-authentication."],"tags":["auth","workspace","http-400"],"backgroundTag":"workspace-not-found-for-token","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}