{"record":{"id":"3adc24971dc3f72c","repo":"FlowiseAI/Flowise","slug":"error-credentialscontroller-getcredentialbyid-w","errorCode":null,"errorMessage":"Error: credentialsController.getCredentialById - workspace ${workspaceId} not found!","messagePattern":"Error: credentialsController\\.getCredentialById - workspace (.+?) not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/credentials/index.ts","lineNumber":71,"sourceCode":"        }\n        const apiResponse = await credentialsService.getAllCredentials(req.query.credentialName, workspaceId)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst getCredentialById = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                `Error: credentialsController.getCredentialById - id not provided!`\n            )\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: credentialsController.getCredentialById - workspace ${workspaceId} not found!`\n            )\n        }\n        const apiResponse = await credentialsService.getCredentialById(req.params.id, workspaceId)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst revealCredentialById = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                `Error: credentialsController.revealCredentialById - id not provided!`\n            )","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/credentials/index.ts#L53-L89","documentation":"Thrown by getCredentialById when req.user.activeWorkspaceId is falsy. Same root cause as errors 780/781: the user is authenticated but their session/JWT does not carry an active workspace. Returns HTTP 404 NOT_FOUND even though the real defect is in the auth claim, not a missing resource.","triggerScenarios":"GET /api/v1/credentials/:id with a valid id but a JWT whose payload omits activeWorkspaceId. Happens after org-level login that never bound a workspace, or when the user's workspace membership was revoked but the token is still valid.","commonSituations":"Token minted in OSS mode reused against enterprise endpoints. Stale cookie after admin reorganized workspaces. Test harness authenticating with a service token that has no workspace claim.","solutions":["Re-login so a fresh JWT includes activeWorkspaceId.","Confirm the user still has membership in the target workspace; re-add if revoked.","Switch active workspace via the workspace-switch endpoint before fetching the credential.","In tests, populate req.user.activeWorkspaceId in your auth stub."],"exampleFix":"// test stub fix\nconst authenticatedReq = {\n  params: { id: 'abc-123' },\n  user: { activeWorkspaceId: 'ws-uuid' } // add this\n}","handlingStrategy":"validation","validationCode":"function assertActiveWorkspace(user: unknown): string {\n  const ws = (user as any)?.activeWorkspaceId\n  if (typeof ws !== 'string' || ws.length === 0) {\n    throw new Error('no activeWorkspaceId — re-login required')\n  }\n  return ws\n}\n\nif (isNonEmptyString(params.id)) {\n  await api.getCredentialById(params.id, assertActiveWorkspace(currentUser))\n}","typeGuard":"function hasActiveWorkspace(u: unknown): u is { activeWorkspaceId: string } {\n  return typeof u === 'object' && u !== null\n    && typeof (u as any).activeWorkspaceId === 'string'\n    && (u as any).activeWorkspaceId.length > 0\n}","tryCatchPattern":"try {\n  await api.getCredentialById(id)\n} catch (e) {\n  if (e.status === 404 && /workspace .* not found/.test(e.message)) {\n    await auth.relogin()\n  } else throw e\n}","preventionTips":["Treat a missing activeWorkspaceId as an auth failure and force re-login rather than retrying in place.","Verify the login strategy writes activeWorkspaceId into the user payload before signing the JWT.","Audit any token-minting code path (SSO, login, workspace-switch) for the activeWorkspaceId field."],"tags":["auth","session","workspace","credentials","flowise"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}