Soar API Setup
Connect Electron to a conforming Unified Platform host: main-process config, host environment, sessions, and verification.
This is the Unified Mode counterpart to Supabase Setup: everything needed to run the desktop app against a conforming Web host instead of a Supabase project. If you haven't picked a mode yet, start at Backend Modes.
No host is privileged by framework name — Next.js, Nuxt, and TanStack Start all work; conformance to the frozen contracts is the compatibility boundary.
1. Deploy a conforming host
Deploy one of the Web templates as a Unified Platform Host and complete its host-side setup (database, Better Auth URL and secret, App API):
Sign up on the Web and verify /api/auth/get-session works before touching the
desktop side. For the cross-template picture, see the
platform Unified Quick Start.
2. Configure the client build
Unified Mode needs two environment values at build time:
# .env
SOAR_BACKEND_MODE=soarApi
# Service root of the host deployment; http://localhost:3000 works for a
# local dev host. Consumed by the MAIN process only — never the renderer.
SOAR_API_BASE_URL=https://your-web-app.example.comThe SUPABASE_* keys can stay unset — the Supabase backend graph is never
imported in this mode. The request Origin is the fixed desktop scheme
soar://.
Configuration errors stop the selected path. A missing or malformed
SOAR_API_BASE_URL fails with a diagnosable error — the other backend is
never initialized as a fallback.
3. Configure the host for this app
On the server (the selected host's deployment environment), the app expects the native support described in Native Authentication:
| Server variable | Why the desktop app needs it |
|---|---|
APP_SCHEME=soar:// | The main process sends Origin: soar:// on every request; Better Auth rejects untrusted origins with 403. |
STORAGE_PROVIDER (+ R2_* in production) | Presigned-upload object storage backing the uploads service. |
| Payment provider config (Creem/Stripe) | The host issues subscription snapshots, checkout URLs, and the management portal that desktop opens. |
DESKTOP_APP_SCHEMES=soar-electron | Only for GitHub/Google sign-in — see step 5. |
Electron Unified intentionally does not implement device tokens or test push — those capabilities are absent rather than silently approximated, so no push credentials are required for desktop. GitHub/Google sign-in is optional and reuses the host's Web OAuth apps, so desktop needs no native OAuth audiences either.
4. Sessions live in an encrypted main-process store
In Unified Mode the app authenticates with Better Auth Bearer tokens (the
set-auth-token response header), not cookies:
- The token is persisted only in a safeStorage-encrypted store owned by the main process, namespaced by app ID, API origin, and build channel — a development session is never restored by a production build.
- The renderer receives a sanitized session over typed IPC; the Bearer
token,
Authorizationheader, and presigned URLs never cross the IPC boundary. - On relaunch the stored session is restored and validated against the server; sign-out clears both the stored token and in-memory state.
- Sessions are database-backed and revocable: revoking a session on the web
invalidates the desktop token immediately, and the app treats
401as "sign in again" — it never retry-loops and never falls back to Supabase auth.
5. Enable GitHub and Google sign-in (optional)
Desktop social sign-in runs in the system browser against the host's
desktop OAuth bridge, which today ships with the
Next.js host.
Nuxt and TanStack Start hosts don't include it: leave SOAR_OAUTH_PROVIDERS
empty against them and the buttons stay hidden. The flow itself is described in
Authentication.
The bridge reuses the host's existing Web GitHub/Google OAuth apps, so there
are no new provider apps or redirect URLs to register. A provider is accepted
only if its GITHUB_CLIENT_ID / GOOGLE_CLIENT_ID is set on the host.
Allow the desktop scheme on the host
# Host deployment environment
DESKTOP_APP_SCHEMES=soar-electronDESKTOP_APP_SCHEMES is the allow-list of schemes the bridge may redirect back
to. It is required in production; development also accepts soar-electron
without it. If you changed the scheme with pnpm rebrand --scheme, list the new
one — the dev default won't cover it.
Turn the buttons on in the client build
# Electron .env
SOAR_OAUTH_PROVIDERS=github,googleA build-time value read by both main (the flow) and the renderer (the buttons). Unknown names are dropped; empty hides the buttons, so a build pointed at a host without the bridge never shows a button that would fail.
Use the same origin as BETTER_AUTH_URL
SOAR_API_BASE_URL must share its origin (scheme, host, and port) with the
host's BETTER_AUTH_URL — for example both http://localhost:3000 locally.
Better Auth binds the OAuth state to a cookie on the host that served the
start URL, while the provider returns to BETTER_AUTH_URL. If they differ —
localhost vs a LAN IP, or www vs the apex domain — the callback fails
with state_mismatch.
Packaged builds also require an HTTPS (or loopback) SOAR_API_BASE_URL before
they will start browser sign-in.
6. Billing through the host
Desktop billing follows the host's subscription state: the app reads the shared subscription snapshot, and checkout or portal flows open provider URLs issued by the host. The main process validates those URLs before opening them externally.
Verify the setup
Run the shared smoke test across both surfaces:
- Sign up or sign in on desktop (email/OTP), then open the same account on the Web.
- If you enabled step 5, sign in with Google and with GitHub. The browser asks to open the app (in development it says "Open Electron?"); confirm, and the app lands on Home. Signing out on the Web leaves the desktop signed in.
- Update the profile on one surface and read it from the other.
- Create, edit, reorder, and delete a todo across both surfaces.
- Upload an avatar and confirm its completion URL is readable.
- Revoke the desktop session from the Web and verify the app returns to sign-in.
- Complete a test checkout from desktop and confirm the same entitlement appears on both surfaces.
- Delete the account from desktop and confirm the cascade on the host.
For a concrete end-to-end walkthrough of one host-and-client pair, follow Next.js + Swift Unified Setup — the steps map onto desktop, minus the Apple/Google ID-token clients and push (desktop uses the browser sign-in from step 5 instead).
Related pages
Backend Modes
The decision page: comparison, mode resolution, and what does not mix.
Environment Variables
Every build key, including SOAR_BACKEND_MODE and SOAR_API_BASE_URL.
IPC
The typed boundary that keeps tokens and presigned URLs in the main process.
Native Authentication
Bearer sessions, email OTP, and the desktop OAuth bridge on the host side.
