{"record":{"id":"a8e8e3120e57ac4d","repo":"Freika/dawarich","slug":"settings-no-api-key-available-for-recalculation","errorCode":null,"errorMessage":"[Settings] No API key available for recalculation status check","messagePattern":"\\[Settings\\] No API key available for recalculation status check","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/javascript/controllers/maps/maplibre/settings_manager.js","lineNumber":468,"sourceCode":"      this.setTransportationSettingsLocked(true)\n      // Start polling for status updates\n      this.startRecalculationPolling()\n    } else {\n      Toast.success(translate(\"messages.transportation_settings_saved\"))\n      this.resetTransportationDirtyState()\n    }\n  }\n\n  // ===== Transportation Mode Recalculation Status =====\n\n  /**\n   * Check the transportation mode recalculation status\n   */\n  async checkRecalculationStatus() {\n    try {\n      const apiKey = this.controller.apiKeyValue\n      if (!apiKey) {\n        console.warn(\n          \"[Settings] No API key available for recalculation status check\",\n        )\n        return\n      }\n\n      const response = await fetch(\n        \"/api/v1/settings/transportation_recalculation_status\",\n        {\n          headers: {\n            Authorization: `Bearer ${apiKey}`,\n            \"Content-Type\": \"application/json\",\n          },\n        },\n      )\n\n      if (!response.ok) {\n        console.warn(\n          \"[Settings] Failed to check recalculation status:\",","sourceCodeStart":450,"sourceCodeEnd":486,"githubUrl":"https://github.com/Freika/dawarich/blob/97fad417c5a11b0eb11157890635e015723a2e97/app/javascript/controllers/maps/maplibre/settings_manager.js#L450-L486","documentation":"The transportation-mode recalculation status poll needs the user's API key as a Bearer token. The Stimulus controller exposes it via apiKeyValue; when that value is blank the manager logs this warning and skips the fetch entirely, leaving the recalculation progress UI unupdated.","triggerScenarios":"The maps controller element lacks its api-key data attribute (anonymous view, template regression, value renamed in an upgrade); the attribute present but empty because the user never generated an API key; a shared or embedded map rendered without a key.","commonSituations":"Fresh installs where the user has not created an API key in settings; view refactors dropping the data attribute; controller value names changed between versions so old markup no longer populates apiKeyValue.","solutions":["Generate an API key in the app's API keys settings if the user has none","Ensure the map element renders data-maps--maplibre-api-key-value with the key (check the DOM)","If the status UI must work without a key, expose recalculation status through a session-authenticated route instead of the API-key endpoint","Treat as expected when keyless — downgrade to debug and render a neutral state"],"exampleFix":"// before\nconst apiKey = this.controller.apiKeyValue\nif (!apiKey) {\n  console.warn(\"[Settings] No API key available for recalculation status check\")\n  return\n}\n// after\nconst apiKey = this.controller.apiKeyValue\nif (!apiKey) {\n  console.debug(\"[Settings] No API key; skipping recalculation status poll\")\n  this.updateRecalculationUI({ status: \"unknown\" }) // neutral UI instead of stale UI\n  return\n}","handlingStrategy":"validation","validationCode":"const key = this.controller.apiKeyValue\nif (typeof key !== \"string\" || key.trim().length === 0) {\n  this.updateRecalculationUI({ status: \"unknown\" })\n  return\n}","typeGuard":"/** @param {unknown} v @returns {v is string} */\nfunction isNonEmptyKey(v) {\n  return typeof v === \"string\" && v.trim().length > 0\n}","tryCatchPattern":null,"preventionTips":["Render the API key data attribute server-side from the current user's active key","Hide recalculation-progress UI when no key is present instead of polling and warning","Keep Stimulus value names in sync between markup and controller definitions across upgrades"],"tags":["dawarich","api-key","stimulus-values","settings","authentication"],"backgroundTag":"missing-api-key","analyzedSha":"97fad417c5a11b0eb11157890635e015723a2e97","analyzedAt":"2026-08-21T17:04:17.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}