feat(integrations): unify OAuth returns and the status envelope

The WHOOP and Fitbit OAuth callbacks redirect back with
`?whoop=connected|error` / `?fitbit=connected|error`, but the settings page
only read that param for Withings, Polar and Oura — a user returning from a
WHOOP or Fitbit round-trip landed on a silently unchanged page with no toast.
Extend the generic return handler to all four OAuth providers, add the
matching connected/failed/error i18n keys across every locale, and invalidate
both the per-card key and the consolidated envelope on a successful return.

Polar and Oura already write the shared IntegrationKey ledger but each fired
its own `/api/<provider>/status` round-trip from the card, so the page issued
one consolidated request plus three per-card ones. Fold Polar and Oura into
`/api/integrations/status` and let the cards read a passed view-model instead
of fetching, retiring the extra round-trips. The per-provider status routes
stay for the iOS and test callers.
This commit is contained in:
Marc-André Bombeck committed 2026-06-15 01:34:30 +02:00
1 parent 38a2c7127e
commit 9430e89889
15 files changed
+583 -42

No files matched your search

@@ -18,7 +18,13 @@ import { queryKeys } from "@/lib/query-keys";
// v1.4.19 Phase A5: the redundant in-card status banner is gone — the
// IntegrationStatusPill now owns state + last-sync presentation, and
// the actionable error message is shown inline above the action row.
export type IntegrationKey = "withings" | "whoop" | "fitbit" | "moodlog";
export type IntegrationKey =
| "withings"
| "whoop"
| "fitbit"
| "moodlog"
| "polar"
| "oura";
export type IntegrationState =
| "connected"
| "error_transient"
@@ -52,6 +58,11 @@ export interface IntegrationStatusViewModel {
// moodLog webhook secret + entry count.
webhookSecret?: string | null;
entryCount?: number;
// Polar / Oura OAuth card: usable-credentials + BYO-key flags. `available`
// greys out the connect button when no credentials resolve; `hasOwnCredentials`
// drives the saved-placeholder UI.
available?: boolean;
hasOwnCredentials?: boolean;
}
export interface IntegrationStatusEnvelope {