{"record":{"id":"77834c326d57a395","repo":"decolua/9router","slug":"no-token-was-returned-by-the-kimchi-authentication","errorCode":null,"errorMessage":"No token was returned by the Kimchi authentication server","messagePattern":"No token was returned by the Kimchi authentication server","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/oauth/services/kimchi.js","lineNumber":83,"sourceCode":"      setTimeout(() => sessions.delete(state), SESSION_TTL_MS).unref?.();\n    });\n\n    const callbackUrl = `http://127.0.0.1:${port}${KIMCHI_CONFIG.callbackPath}`;\n    const authUrl = buildKimchiAuthUrl(callbackUrl, state);\n    return { authUrl, port, state, result, close };\n  }\n\n  async _handleCallback(params, expectedState) {\n    if (params.error) {\n      throw new Error(params.error_description || params.error);\n    }\n    const candidate = params.state;\n    if (!candidate || candidate !== expectedState) {\n      throw new Error(\"This request isn't valid. Please restart the Kimchi login flow.\");\n    }\n    const token = params.token;\n    if (!token) {\n      throw new Error(\"No token was returned by the Kimchi authentication server\");\n    }\n    const check = await this.validateToken(token);\n    if (!check.valid) {\n      throw new Error(check.error || \"Kimchi token validation failed\");\n    }\n    return { token };\n  }\n\n  async fetchProfile(token) {\n    try {\n      const res = await fetch(KIMCHI_CONFIG.meUrl, {\n        headers: { Authorization: `Bearer ${token}` },\n      });\n      if (!res.ok) return {};\n      const j = await res.json();\n      return { displayName: j.name, email: j.email, username: j.username };\n    } catch {\n      return {};","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/oauth/services/kimchi.js#L65-L101","documentation":"Thrown by KimchiService._handleCallback() when the callback passes the error and state checks but carries no `token` query parameter. Kimchi's simplified browser login delivers the access token directly on the callback URL (no code exchange); its absence means the Kimchi web app redirected back without completing token issuance.","triggerScenarios":"The Kimchi web app redirects to the local callback with a valid `state` but no `token` — login succeeded partially (e.g. account selection done but token issuance failed), the web app's token-generation step errored, or a non-auth request with a matching state reached the server.","commonSituations":"Kimchi backend failing to mint a token after successful auth; a truncated/partial redirect; the web app version changing callback shape so the token lands under a different param name; retry logic hitting the callback endpoint without token.","solutions":["Restart the Kimchi login flow and complete all steps in the browser until fully finished.","Check whether the Kimchi web app still puts the token in the `token` query param (API change → update this handler).","Look at the Kimchi web app/backend logs for token-issuance failures on your account.","Retry later if Kimchi reports a transient backend problem."],"exampleFix":"// before\nif (!token) {\n  throw new Error(\"No token was returned by the Kimchi authentication server\");\n}\n// after\nif (!token) {\n  throw new Error(`No token was returned by the Kimchi authentication server. Callback params: ${Object.keys(params).join(\", \") || \"(none)\"}`);\n}","handlingStrategy":"validation","validationCode":"// Check the token param before proceeding\nfunction hasToken(params) {\n  return params != null && typeof params.token === \"string\" && params.token.length > 0;\n}","typeGuard":"function isTokenCallback(p) {\n  return typeof p === \"object\" && p !== null && typeof p.token === \"string\" && p.token.length > 0;\n}","tryCatchPattern":"try {\n  const outcome = await session.result;\n  if (outcome.error && /No token was returned/.test(outcome.error)) {\n    console.error(\"Callback had a valid state but no token — Kimchi failed to issue one; retry the login.\");\n  }\n} catch { /* errors are resolved into the result, not rejected */ }","preventionTips":["Finish every step in the Kimchi web app until it redirects back with the token.","After any Kimchi web app update, confirm the callback still uses the `token` query param.","Log callback param names when this fires to detect upstream shape changes.","Retry once after a transient backend failure before reporting to the user."],"tags":["oauth","callback","token","kimchi"],"backgroundTag":"missing-oauth-token-callback","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}