Fix route compute 401: use authenticated API client
The route editor called fetch() directly for /api/v1/routes/compute without the bearer token. Now uses the API client which injects auth headers and handles 401 auto-refresh. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3ad2ef9006
commit
5c4c0ae49d
2 changed files with 12 additions and 18 deletions
|
|
@ -113,6 +113,13 @@ export function updateRoute(id: string, data: { name?: string; description?: str
|
|||
});
|
||||
}
|
||||
|
||||
export function computeRoute(waypoints: Array<{ lat: number; lon: number }>, profile = "fastbike") {
|
||||
return request<unknown>("/routes/compute", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ waypoints, profile }),
|
||||
});
|
||||
}
|
||||
|
||||
// --- Activities ---
|
||||
|
||||
export async function listActivities(cursor?: string, limit = 20) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { useState, useCallback, useRef } from "react";
|
||||
import type { Waypoint } from "@trails-cool/types";
|
||||
import type { RouteDetail } from "../api-client";
|
||||
import { updateRoute } from "../api-client";
|
||||
import { getServerUrl } from "../server-config";
|
||||
import { updateRoute, computeRoute as apiComputeRoute } from "../api-client";
|
||||
import { generateGpx } from "@trails-cool/gpx";
|
||||
|
||||
export interface RouteSegment {
|
||||
|
|
@ -44,22 +43,10 @@ export function useRouteEditor(route: RouteDetail) {
|
|||
setState((s) => ({ ...s, computing: true, error: null }));
|
||||
|
||||
try {
|
||||
const serverUrl = await getServerUrl();
|
||||
const resp = await fetch(`${serverUrl}/api/v1/routes/compute`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
waypoints: waypoints.map((w) => ({ lat: w.lat, lon: w.lon })),
|
||||
profile: route.routingProfile ?? "fastbike",
|
||||
}),
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
setState((s) => ({ ...s, computing: false, error: "Route computation failed" }));
|
||||
return;
|
||||
}
|
||||
|
||||
const geojson = await resp.json();
|
||||
const geojson = await apiComputeRoute(
|
||||
waypoints.map((w) => ({ lat: w.lat, lon: w.lon })),
|
||||
route.routingProfile ?? "fastbike",
|
||||
);
|
||||
const coords = extractCoordsFromGeojson(geojson);
|
||||
setState((s) => ({
|
||||
...s,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue