Add Komoot import with public (bio verification) and authenticated modes
Two-mode import: public mode verifies Komoot account ownership by checking that the user's trails.cool profile URL appears in their Komoot bio — no credentials stored. Authenticated mode uses email + password (AES-256-GCM encrypted) to import private tours as well. Includes unit tests for crypto/komoot client and E2E tests for the full connect + import flow. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b63fd1a303
commit
03304c354b
22 changed files with 1612 additions and 4 deletions
41
apps/journal/app/routes/api.sync.komoot.verify.ts
Normal file
41
apps/journal/app/routes/api.sync.komoot.verify.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// POST /api/sync/komoot/verify
|
||||
// Verifies Komoot public profile ownership by checking that the user's
|
||||
// trails.cool profile URL appears in their Komoot bio.
|
||||
// On success, creates or replaces the connected service row in public mode.
|
||||
|
||||
import { data, redirect } from "react-router";
|
||||
import type { Route } from "./+types/api.sync.komoot.verify";
|
||||
import { getSessionUser } from "~/lib/auth/session.server";
|
||||
import { parseKomootUserId, verifyKomootOwnership } from "~/lib/komoot.server";
|
||||
import { link } from "~/lib/connected-services/manager";
|
||||
export async function action({ request }: Route.ActionArgs) {
|
||||
const user = await getSessionUser(request);
|
||||
if (!user) return redirect("/auth/login");
|
||||
|
||||
const body = (await request.json()) as { komootProfileUrl?: string };
|
||||
const input = body.komootProfileUrl?.trim() ?? "";
|
||||
|
||||
const komootUserId = parseKomootUserId(input);
|
||||
if (!komootUserId) {
|
||||
return data({ error: "invalid_url" }, { status: 400 });
|
||||
}
|
||||
|
||||
const origin = process.env.ORIGIN ?? "http://localhost:3000";
|
||||
const trailsProfileUrl = `${origin}/users/${user.username}`;
|
||||
|
||||
const verified = await verifyKomootOwnership(komootUserId, trailsProfileUrl);
|
||||
if (!verified) {
|
||||
return data({ error: "not_verified" }, { status: 422 });
|
||||
}
|
||||
|
||||
await link({
|
||||
userId: user.id,
|
||||
provider: "komoot",
|
||||
credentialKind: "public",
|
||||
credentials: { mode: "public", komootUserId },
|
||||
providerUserId: komootUserId,
|
||||
grantedScopes: [],
|
||||
});
|
||||
|
||||
return data({ success: true });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue