Spaces:
Sleeping
Sleeping
Commit
·
1f74bee
1
Parent(s):
6c889e3
Update MapCanvas.tsx
Browse files
web/src/components/map/MapCanvas.tsx
CHANGED
|
@@ -57,20 +57,58 @@ export default function MapCanvas({
|
|
| 57 |
useEffect(() => {
|
| 58 |
fetch("/config/runtime", { cache: "no-store" })
|
| 59 |
.then((r) => (r.ok ? r.json() : Promise.reject(new Error(r.statusText))))
|
| 60 |
-
.then(
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
}, []);
|
| 63 |
|
| 64 |
if (err) return <div>Map config error: {err}</div>;
|
| 65 |
-
if (!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
return (
|
| 67 |
<APIProvider
|
| 68 |
-
apiKey={
|
| 69 |
libraries={["places", "marker"]}
|
| 70 |
>
|
| 71 |
<Map
|
| 72 |
className="map"
|
| 73 |
-
mapId={
|
| 74 |
defaultCenter={{ lat: 39, lng: -98 }}
|
| 75 |
defaultZoom={4}
|
| 76 |
gestureHandling="greedy"
|
|
|
|
| 57 |
useEffect(() => {
|
| 58 |
fetch("/config/runtime", { cache: "no-store" })
|
| 59 |
.then((r) => (r.ok ? r.json() : Promise.reject(new Error(r.statusText))))
|
| 60 |
+
.then((json) => {
|
| 61 |
+
// Safe, partial logging (don’t leak the full key)
|
| 62 |
+
const k = json?.VITE_GOOGLE_MAPS_API_KEY;
|
| 63 |
+
const mid = json?.VITE_GOOGLE_MAPS_MAP_ID;
|
| 64 |
+
console.log("[PulseMap] /config/runtime:", {
|
| 65 |
+
key_present: !!k,
|
| 66 |
+
key_len: k?.length ?? 0,
|
| 67 |
+
key_preview: k ? `${k.slice(0, 6)}...${k.slice(-4)}` : null,
|
| 68 |
+
map_id_present: !!mid,
|
| 69 |
+
map_id_preview: mid ? `${mid.slice(0, 5)}...` : null,
|
| 70 |
+
});
|
| 71 |
+
setCfg(json);
|
| 72 |
+
})
|
| 73 |
+
.catch((e) => {
|
| 74 |
+
console.error("[PulseMap] runtime config fetch failed:", e);
|
| 75 |
+
setErr(e.message);
|
| 76 |
+
});
|
| 77 |
+
}, []);
|
| 78 |
+
const effectiveKey = cfg?.VITE_GOOGLE_MAPS_API_KEY ?? GMAPS_KEY;
|
| 79 |
+
const effectiveMapId = cfg?.VITE_GOOGLE_MAPS_MAP_ID ?? MAP_ID;
|
| 80 |
+
|
| 81 |
+
useEffect(() => {
|
| 82 |
+
console.log("[PulseMap] build-time env:", {
|
| 83 |
+
GMAPS_KEY_present: !!GMAPS_KEY,
|
| 84 |
+
GMAPS_KEY_len: GMAPS_KEY?.length ?? 0,
|
| 85 |
+
GMAPS_KEY_preview: GMAPS_KEY
|
| 86 |
+
? `${GMAPS_KEY.slice(0, 6)}...${GMAPS_KEY.slice(-4)}`
|
| 87 |
+
: null,
|
| 88 |
+
MAP_ID_present: !!MAP_ID,
|
| 89 |
+
MAP_ID_preview: MAP_ID ? `${MAP_ID.slice(0, 5)}...` : null,
|
| 90 |
+
});
|
| 91 |
}, []);
|
| 92 |
|
| 93 |
if (err) return <div>Map config error: {err}</div>;
|
| 94 |
+
if (!effectiveKey) {
|
| 95 |
+
console.warn(
|
| 96 |
+
"[PulseMap] No Google Maps API key found from runtime or build-time."
|
| 97 |
+
);
|
| 98 |
+
return <div>No Google Maps API key. Check /config/runtime and env.</div>;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
// TEMP: isolate auth failures by removing mapId during testing
|
| 102 |
+
const testingMapId: string | undefined = undefined; // <- set to 'effectiveMapId' once key works
|
| 103 |
+
|
| 104 |
return (
|
| 105 |
<APIProvider
|
| 106 |
+
apiKey={effectiveKey || GMAPS_KEY}
|
| 107 |
libraries={["places", "marker"]}
|
| 108 |
>
|
| 109 |
<Map
|
| 110 |
className="map"
|
| 111 |
+
mapId={testingMapId || MAP_ID || undefined}
|
| 112 |
defaultCenter={{ lat: 39, lng: -98 }}
|
| 113 |
defaultZoom={4}
|
| 114 |
gestureHandling="greedy"
|