{"record":{"id":"a6483ed28bb8457e","repo":"calcom/cal.diy","slug":"unable-to-generate-token","errorCode":null,"errorMessage":"Unable to generate token","messagePattern":"Unable to generate token","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"example-apps/credential-sync/pages/api/getToken.ts","lineNumber":32,"sourceCode":"      return res.status(403).json({ message: \"Invalid secret\" });\n    }\n\n    const calcomUserId = req.body.calcomUserId;\n    const appSlug = req.body.appSlug;\n    console.log(\"getToken Params\", {\n      calcomUserId,\n      appSlug,\n    });\n    let accessToken;\n    if (appSlug === \"google-calendar\") {\n      accessToken = await generateGoogleCalendarAccessToken();\n    } else if (appSlug === \"zoom\") {\n      accessToken = await generateZoomAccessToken();\n    } else {\n      throw new Error(\"Unhandled values\");\n    }\n    if (!accessToken) {\n      throw new Error(\"Unable to generate token\");\n    }\n    res.status(200).json({\n      _1: true,\n      access_token: accessToken,\n    });\n  } catch (e) {\n    res.status(500).json({ error: e.message });\n  }\n}\n","sourceCodeStart":14,"sourceCodeEnd":42,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/example-apps/credential-sync/pages/api/getToken.ts#L14-L42","documentation":"Thrown by the example credential-sync getToken endpoint when the chosen token-generation function (generateGoogleCalendarAccessToken or generateZoomAccessToken) returned a falsy value. This indicates the provider-specific generation logic ran but produced no usable token. Caught and returned as a 500 response.","triggerScenarios":"POST /api/getToken with a supported appSlug, but the underlying generator returned null/undefined/empty string. Typically because the example app's service-account credentials, refresh tokens, or OAuth client secrets are missing or invalid inside lib/integrations.","commonSituations":"Example app env vars (Google service account JSON, Zoom OAuth secrets) not set; refresh token expired or revoked; the generator silently returns undefined on a caught internal error; clock skew or quota limits causing the provider to return an empty token.","solutions":["Set the provider credentials required by lib/integrations (e.g. Google service account, Zoom client secret/refresh token) in the example app environment.","Add logging inside the generator to see why it returned empty (provider error, expired refresh token).","Re-authorize the provider to obtain a fresh refresh token.","Return a non-empty token from the generator or throw a descriptive error instead of returning undefined."],"exampleFix":"// before - generator returns undefined silently\nexport async function generateZoomAccessToken() {\n  const r = await fetch(...);\n  return r.ok ? (await r.json()).access_token : undefined;\n}\n// after - throw with reason so getToken can surface it\nexport async function generateZoomAccessToken() {\n  const r = await fetch(...);\n  if (!r.ok) throw new Error(`Zoom token HTTP ${r.status}`);\n  return (await r.json()).access_token;\n}","handlingStrategy":"try-catch","validationCode":"if (!accessToken) {\n  // surface a clear reason instead of a generic throw\n  return res.status(502).json({ error: `Token generation returned empty for ${appSlug}` });\n}","typeGuard":"function isNonEmptyToken(t: unknown): t is string {\n  return typeof t === 'string' && t.length > 0;\n}","tryCatchPattern":"try {\n  accessToken = appSlug === 'google-calendar' ? await generateGoogleCalendarAccessToken() : await generateZoomAccessToken();\n} catch (genError) {\n  return res.status(502).json({ error: `Generator failed: ${genError.message}` });\n}\nif (!accessToken) return res.status(502).json({ error: 'Empty token from provider' });","preventionTips":["Have generators throw a descriptive error instead of returning undefined.","Set and verify provider credentials (Google service account, Zoom secrets) in the example app env.","Log provider HTTP responses inside generators to diagnose empty tokens."],"tags":["credential-sync","example-app","oauth","tokens"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}