appforge phase 7. Optional account in 1.0 with Clerk driven through its CLI (one-time code by email or SMS, no password), Supabase as third-party auth with RLS, guest profile merge, adding an email or phone to an account, account deletion.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Auth?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/mrasoahaingo-auth)
---
name: auth
description: appforge phase 7. Optional account in 1.0 with Clerk driven through its CLI (one-time code by email or SMS, no password), Supabase as third-party auth with RLS, guest profile merge, adding an email or phone to an account, account deletion.
disable-model-invocation: true
---
# Phase 7: optional account
The account is **offered as a benefit** ("Save your progress"), after the first use, and can be declined without losing anything. It never sits in front of the main gesture.
Skills: `clerk-cli` (preferred over the dashboard), `clerk-expo`, then `clerk-vercel-prod` to go to production.
## Clerk through the CLI
Always `CLERK_MODE=agent clerk … < /dev/null`, otherwise `config patch` waits on standard input.
1. `clerk apps create`, then record the app ID and the dev instance domain in the log.
2. `clerk config pull`, then `config patch --dry-run`, then `--yes`, to get:
- email with a one-time code (not the email link);
- phone number with SMS code as an identifier;
- no password;
- neither email nor phone required, because an account created by SMS has no email;
- Native API enabled;
- the `{"role":"authenticated"}` claim in `session.claims` (Supabase integration).
3. **SMS**: blocked by default to almost every country. `PATCH /instance/communication` with `blocked_country_codes`. Real SMS are billed: in development, use the test numbers `+15555550100` to `0199`, code `424242`.
4. **Apple and Google**: off at first, in Clerk and in the app (`isSocialSignInEnabled = false`). Apple becomes mandatory as soon as Google is offered on iOS.
5. Check from the public side: `curl https://<FAPI domain>/v1/environment?_is_native=true`.
6. **Production instance** (after the user's `clerk deploy`): add the DNS records it lists **plus TXT `_dmarc` = `v=DMARC1; p=none;`**, which only the dashboard's Domains page shows (email stays 3/4 and `deploy status` "pending" without it; Gmail and Yahoo want DMARC anyway); on Vercel DNS pass `--scope <vercel_scope>`, the CLI may sit on another team. Then "Verify Records" on that page. It it copies the dev config, **except the Native API**, which neither `config` nor the Backend API exposes. The user switches it on in the dashboard (Native applications page of the production instance); until then the production FAPI answers `native_api_disabled` and the app signs nobody in. Then re-check step 5 on `clerk.<domain>` and the SMS countries (`GET /instance/communication --instance prod`) against the listing's storefronts (en-GB listing → GB).
7. **Production keys and webhook**, without a secret ever printed:
- Supabase secret key: `supabase projects api-keys -o json` returns it **masked** (`sb_secret_xxxx·····`); take it from the Management API, `GET /v1/projects/<ref>/api-keys?reveal=true` (token in the Keychain, service "Supabase CLI"), and check it with one REST call before using it.
- Clerk webhook: `clerk api /webhooks/svix_url -X POST --instance prod` gives a portal URL whose `#key=` holds `{appId, oneTimeToken, region}`; exchange the token at `https://api.<region>.svix.com/api/v1/auth/one-time-token`, create the endpoint (`user.created`, `user.updated`, `user.deleted`), read its secret, and pipe it into `vercel env add CLERK_WEBHOOK_SIGNING_SECRET production --sensitive`.
- EAS `production`: the `EXPO_PUBLIC_*` keys (pk_live, Supabase URL and publishable key, SMS flag) **and `EXPO_PUBLIC_WEB_URL`**.
- Verify end to end: no signature → 400 (503 means a variable is missing), then a throwaway user created and deleted in Clerk prod must create and remove its profile row; redeploy after every variable change.
## In the app
- **Local guest profile** merged into the account on first sign-in. Clerk has no anonymous session.
- **One code flow for both channels**: a single two-step screen (email or phone, then the 6-digit code), resend after a delay, "Change email/number", a clear message when the code is wrong. Fastkind first used an email link, which depended on the deployed website; the code flow removed that dependency and halved the sign-in code.
- Adding an email or phone to the account (below) is verified by code too.
- **Add an email or phone** to the existing account from the account card, so the same person does not end up with two accounts. A later Google sign-in finds the account through the **verified** email.
- **Delete my account**, mandatory for the App Store. Two taps, with a text that says what gets erased. The Clerk account is deleted, notifications unregistered, and the subscriber deleted at RevenueCat if Plus exists.
## Supabase
- **Local stack after `supabase link`**: the link writes the hosted project's versions to `supabase/.temp/*-version`; a hosted PostgREST version may have no Docker image (`rest-version` v17.1, "manifest unknown"), and `supabase start` hangs pulling it. Delete `supabase/.temp/rest-version` (git-ignored) before `supabase start`; `supabase db push --linked` still targets the hosted project.
- **A deleted account stays deleted.** Svix retries failed deliveries for hours and does not order them: a `user.created` that failed once can land after `user.deleted` (Grassling, 2026-12-04: a deleted test user's profile came back with its email). Keep a `deleted_accounts` tombstone (the Clerk ID only), skip profile inserts for tombstoned IDs in a `before insert` trigger (return null: the webhook answers 200 and Svix stops), and make both deletion paths (`delete_my_data()` from the app, `forget_account()` from the webhook) tombstone first. Test it in pgTAP and once in production by replaying the `user.created` through Svix after the deletion. Say in the privacy page that only the random technical ID is kept.
- Clerk as third-party auth. RLS on `(select auth.jwt()->>'sub')`, user keys as `text`.
- Triggers that force `user_id`, and "the most recent version wins" arbitration (`client_updated_at`).
- pgTAP tests (`pnpm db:test`), then types (`pnpm db:types`). Model: `<reference_app>/supabase/`.
- Clerk webhook (`svix`) to `apps/web` for the `profiles` mirror. It is not on the critical path: a trigger creates the profile if the webhook is late.
- Production (it ships in 1.0): Clerk production instance (`clerk-vercel-prod`), `supabase link` then `supabase db push`, plus the variables on Vercel and on EAS in the `production` environment (the `production` build profile declares `"environment": "production"`). `LEGAL.features.accounts = true`, with the legal pages reread.
## End-to-end check
On the simulator, with the harness: `sign-in?channel=sms&phone=%2B15555550100`, then `&code=424242`. The flow is complete when:
1. a wrong code shows its message without creating an account;
2. the right code signs in;
3. the token is accepted by Supabase;
4. data created as a guest shows up on the server;
5. a second sync creates no duplicate.
## Done when
The 5 points above are verified, along with account deletion, and the log says how.