Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

02_connect-setup.md

77 lines5.1 KB

1# T3 Connect setup
2​
3Deployment and client configuration for T3 Connect. See [T3 Connect](../internals/06_t3-connect.md) for trust boundaries and [infra/relay/README.md](../../infra/relay/README.md#deployment) for relay provisioning.
4​
5## Public application configuration
6​
7T3 Connect is disabled in a fresh clone. Copy `.env.example` to `.env` for production, or set these public identifiers in `.env` / `.env.local` (process env > `.env.local` > `.env`):
8​
9```dotenv
10T3CODE_CLERK_PUBLISHABLE_KEY=<publishable key>
11T3CODE_CLERK_JWT_TEMPLATE=<JWT template name>
12T3CODE_CLERK_CLI_OAUTH_CLIENT_ID=<public OAuth application client ID>
13T3CODE_RELAY_URL=https://relay.example.com
14```
15​
16`CLERK_SECRET_KEY` belongs only in relay secrets, never in client config. Client and bundled-server builds embed these values at build time; EAS preview/production environments need the publishable key, JWT template, and relay URL.
17​
18## Clerk setup
19​
20### CLI OAuth application
21​
22Create a public OAuth application in Clerk (authorization code + PKCE):
23​
241. Redirect URI: `http://127.0.0.1:34338/callback`
252. Scopes: `openid`, `profile`, `email`, `offline_access`
263. Enable **Device authorization grant** (required for headless/SSH login; Clerk enables it per account on request).
274. Set `T3CODE_CLERK_CLI_OAUTH_CLIENT_ID` to its public client ID.
28​
29### JWT template
30​
31Create a Clerk JWT template named `t3-relay` with `{ "aud": "t3-code-relay" }`. Set `T3CODE_CLERK_JWT_TEMPLATE=t3-relay` on clients and `CLERK_JWT_AUDIENCE=t3-code-relay` on the relay.
32​
33### Desktop OAuth redirects
34​
35Enable Clerk's Native API, add `t3code-dev://app/` and `t3code://app/` to the SSO redirect allowlist, and add `t3code-dev://app` and `t3code://app` to `allowed_origins` via `PATCH https://api.clerk.com/v1/instance` (preserving existing entries).
36​
37### Android native sign-in redirects
38​
39In Clerk **Native applications > Allowlist for mobile SSO redirect**, allow each variant's callback:
40​
41| Variant | Callback |
42| ----------- | --------------------------------------------- |
43| Development | `clerk://com.t3tools.t3code.dev.callback` |
44| Preview | `clerk://com.t3tools.t3code.preview.callback` |
45| Production | `clerk://com.t3tools.t3code.callback` |
46​
47### Restricting sign-ups
48​
49Use Clerk's allowlist or Restricted mode for new sign-ups (an enabled empty allowlist blocks all sign-ups). Ban the account in Clerk to revoke existing sessions.
50​
51### Account deletion webhook
52​
53Under Clerk **Webhooks**, add an endpoint at `https://<relay domain>/v1/webhooks/clerk` subscribed to `user.deleted`, and set its signing secret as `CLERK_WEBHOOK_SIGNING_SECRET` on the relay. Deleting a user in Clerk then records the deletion, and the relay's five-minute cron tears down their managed tunnels and deletes their relay rows, retrying until a pass succeeds after the user's relay tokens have expired. Each deletion is a row in `relay_account_deletions`: pending while `completed_at` is null (`attempts` climbing means it keeps failing), then kept as the record of which account was deleted and when. Before restoring the relay database from a backup, export `relay_account_deletions`: the backup may predate some requests. After the restore, insert the exported rows that are missing, then set `completed_at` back to null on every row so the restored data is deleted again. Without the secret the route answers 404.
54​
55## Android FCM push setup
56​
57The relay sends Android push notifications directly via FCM HTTP v1 (no Expo Push account required):
58​
591. Register each Android package (`com.t3tools.t3code.{dev,preview}` / `com.t3tools.t3code`) in Firebase and download `google-services.json`.
602. Pass `T3CODE_ANDROID_GOOGLE_SERVICES_FILE=/abs/path/google-services.json` when prebuilding/building locally or as an EAS file variable (available to fingerprint generation as well).
613. Enable the FCM API and store the Firebase service-account JSON only in the relay's `FCM_SERVICE_ACCOUNT` secret (never in EAS app env or the repo). Set `APNS_ENABLED=false` for an Android-only relay stage.
624. For local smoke/watch verification without deploying a relay, use `vp run push:android:smoke` and `vp run push:android:watch` from `infra/relay`.
63​
64## Desktop passkeys
65​
66For a signed macOS build (`com.t3tools.t3code`):
67​
681. Create an explicit macOS App ID with **Associated Domains** and a matching distribution provisioning profile.
692. In Clerk Native API settings, add an iOS app with the same Apple Team ID and bundle ID, and verify `https://<frontend-api>/.well-known/apple-app-site-association` includes `<TEAM_ID>.com.t3tools.t3code`.
703. Configure signing per [Apple signing and notarization](./03_release.md#apple-signing-and-notarization-macos). Local signed builds use `T3CODE_APPLE_TEAM_ID`, `T3CODE_MACOS_PROVISIONING_PROFILE`, and optionally `T3CODE_CLERK_PASSKEY_RP_DOMAINS`. Bump the build version after changing Associated Domains so macOS refreshes cached Shared Web Credentials.
71​
72Unsigned `dev:desktop` cannot exercise passkeys. For renderer HMR with passkeys, launch an installed signed build against `vp run dev:web`:
73​
74```sh
75VITE_DEV_SERVER_URL=http://127.0.0.1:5733 T3CODE_PORT=13773 \
76 "/Applications/T3 Code (Alpha).app/Contents/MacOS/T3 Code (Alpha)"
77```