{"record":{"id":"6bfe174491307301","repo":"decolua/9router","slug":"zed-credential-is-missing-userid-or-accesstoken","errorCode":null,"errorMessage":"Zed credential is missing userId or accessToken","messagePattern":"Zed credential is missing userId or accessToken","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"open-sse/shared/zedAuth.js","lineNumber":164,"sourceCode":"      return crypto\n        .privateDecrypt(\n          { key: privateKey, padding: crypto.constants.RSA_PKCS1_PADDING },\n          encrypted,\n        )\n        .toString(\"utf8\");\n    } catch {\n      const message = oaepError instanceof Error ? oaepError.message : String(oaepError);\n      throw new Error(`Failed to decrypt Zed access token: ${message}`);\n    }\n  }\n}\n\nexport function buildZedUserAuthHeader(credentials) {\n  const psd = credentials?.providerSpecificData || {};\n  const userId = psd.userId || credentials?.userId;\n  const accessToken = credentials?.accessToken || credentials?.apiKey;\n  if (!userId || !accessToken) {\n    throw new Error(\"Zed credential is missing userId or accessToken\");\n  }\n  return `${userId} ${accessToken}`;\n}\n\nfunction getSystemId(credentials) {\n  return String(\n    credentials?.providerSpecificData?.systemId || credentials?.systemId || \"\",\n  );\n}\n\nasync function fetchJson(url, options, proxyOptions = null) {\n  const res = await proxyAwareFetch(url, options, proxyOptions);\n  const text = await res.text();\n  let data = null;\n  if (text) {\n    try {\n      data = JSON.parse(text);\n    } catch {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/open-sse/shared/zedAuth.js#L146-L182","documentation":"buildZedUserAuthHeader builds the Zed `Authorization: \"<userId> <accessToken>\"` header from credentials. It reads userId from providerSpecificData.userId or credentials.userId, and the token from credentials.accessToken or credentials.apiKey. If either is absent it throws, since Zed's user-auth endpoints cannot be called without both parts.","triggerScenarios":"Calling fetchZedAuthenticatedUser/fetchZedLlmToken with a credentials object that lacks userId or accessToken/apiKey — e.g. an API-key-only credential that never went through the Zed OAuth callback, or a partially-saved credential row.","commonSituations":"User added a Zed provider with only an API key (no OAuth sign-in); credential sync/import dropped providerSpecificData.userId; the decrypt step failed earlier so accessToken was never persisted.","solutions":["Complete the Zed OAuth sign-in so the credential stores userId (in providerSpecificData or top-level) and accessToken.","Check credentials.providerSpecificData.userId and credentials.accessToken directly before calling; fill in whatever is missing.","If you have an apiKey instead of an OAuth token, ensure it is set on credentials.accessToken or credentials.apiKey — the header builder accepts apiKey as the token.","Re-save the credential in the dashboard to make sure partial data wasn't persisted."],"exampleFix":"// before\nbuildZedUserAuthHeader({ accessToken: \"tok\" }); // no userId\n// after\nbuildZedUserAuthHeader({ providerSpecificData: { userId: \"42\" }, accessToken: \"tok\" });","handlingStrategy":"validation","validationCode":"function canBuildZedHeader(cred) {\n  const psd = cred?.providerSpecificData || {};\n  return Boolean((psd.userId || cred?.userId) && (cred?.accessToken || cred?.apiKey));\n}\n// guard: if (!canBuildZedHeader(credentials)) prompt OAuth sign-in before any Zed API call;\n","typeGuard":"const hasZedCredential = (c) => Boolean(c && (c.providerSpecificData?.userId || c.userId) && (c.accessToken || c.apiKey));","tryCatchPattern":"let authHeader;\ntry {\n  authHeader = buildZedUserAuthHeader(credentials);\n} catch (e) {\n  // credential incomplete — kick off Zed OAuth sign-in flow to fill userId/accessToken\n}","preventionTips":["Require the OAuth callback step to complete before saving a Zed provider credential.","Validate credentials on save (both userId and accessToken present).","Don't import/sync partial Zed credentials; carry providerSpecificData.userId along."],"tags":["auth","validation","zed","credentials"],"backgroundTag":"missing-credentials","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}