> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bbrands.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Step-by-step rollout

> What to configure in Apple, Supabase, 1Password, the Release Train, the flags and the stores so authentication works in the app and on the web.

This page is the full path from the moment the authentication code reaches `develop` until the
version is published and mandatory in both stores. The detail of every console lives in the
repository runbook,
[`docs/operations/oauth-providers.md`](https://github.com/bbrandslab/bbrands-monorepo/blob/develop/docs/operations/oauth-providers.md),
which is the source of truth.

![After the merge to develop the alpha tag is created. In each environment, development, certification and production, Apple, Supabase and 1Password are configured first, then the Release Train runs, then the flags are synced and turned on, and finally the environment is tested. Production ends with App Review and the mandatory release.](https://mintcdn.com/bbrands/-6vpv4Xb-mMAz8bx/images/authenticate/rollout-sequence.svg?fit=max\&auto=format\&n=-6vpv4Xb-mMAz8bx\&q=85\&s=da9e364e687bfe29df71fad99df469c3)

Rollout order per environment

## The three ordering rules

> [card] One environment at a time
>
> development → certification → production. Do not move on without testing the previous one.

> [card] Consoles before the train
>
> The Release Train starts with Sync Env and ends with the EAS build. Apple, Supabase and 1Password
> must be ready before it runs.

> [card] Flags last
>
> A flag turned on before the deploy shows the button, but the sign-in fails.

## How a tag reaches each environment

Merging into `develop` deploys nothing: `release.yml` only creates the `YYYY.M.P-alpha.N` tag and its
GitHub Release. Each environment is rolled out by hand with the **Release Train** workflow, which
always starts from a tag.

| Tag | How it is created | Allowed environments | Approvals |
| - | - | - | - |
| `-alpha.N` | Merge to `develop` (automatic) | development | — |
| `-rc.N` | `pnpm pr:rc` and merge `develop → release` | development, certification | 1 reviewer |
| Stable | `pnpm pr:release` and merge `release → master` | all three | 2 reviewers |

The train runs, in order: Sync Env → Deploy → database migrations and IdP → Wave-0 QA → EAS builds.
The EAS build takes its version from the tag, so the version in `app.config.js` is **not bumped by
hand**.

## Step 0 · Apple Developer, once

These two tasks cover all three environments and are done before the first train.

**1. Capability on the five App IDs**

Certificates, Identifiers & Profiles → Identifiers → enable **Sign in with Apple** on
`com.maihuego.application.dev`, `.sandbox`, `.cert`, `.preprod` and `com.maihuego.application`.

* Primaries (**Enable as a primary App ID**): `.dev`, `.cert` and the production one.
* `.sandbox` is **grouped with** `.dev`, and `.preprod` with the production one, so a person sees
  a single consent per environment.
* On each primary, **Server-to-Server Notification Endpoint** =
  `https://<environment horizon-api>/api/v3/auth/oauth/apple/notifications`.

**2. Private Email Relay**

Services → **Sign in with Apple for Email Communication** → register `maihuego.com`,
`contacto@maihuego.com`, the Resend return-path domain and the SMTP sender of each Supabase
project. Without it, mail to `@privaterelay.appleid.com` addresses bounces (magic links and
security e-mails included). Apple requires SPF; DKIM is recommended.

> [!WARNING]
>
> If the capability is not enabled before the train, the EAS build ships without the entitlement and
> the native Apple sign-in fails on iOS.

## Step 1 · Development

**1. Apple: Services ID and key**

* Services ID `com.maihuego.signin.dev`, with Sign in with Apple → Primary App ID `.dev`, domain
  `development.supabase.bbrands.io` and Return URL
  `https://development.supabase.bbrands.io/auth/v1/callback`.
* `.p8` key "Sign in with Apple development", bound to the primary. It downloads **only once**:
  write down the Key ID and the Team ID and keep the file in 1Password.

**2. Supabase development**

* Authentication → Sign In / Providers → **Apple**: enable.
  * Client IDs: the Services ID and the environment bundle IDs, comma separated
    (`com.maihuego.signin.dev,com.maihuego.application.dev,com.maihuego.application.sandbox`).
    Without the bundle ID the native iOS sign-in fails.
  * Secret Key: the ES256 JWT signed with the `.p8` (six months at most; the runbook has the
    script).
* URL Configuration → Redirect URLs: add
  `https://development.api.bbrands.io/api/v3/auth/login/oauth/apple/callback**`.
* E-mail link expiry (`MAILER_OTP_EXP`) = **3600** seconds.

**3. 1Password development**

| App | Variable | Value |
| - | - | - |
| horizon-api | `APPLE_TEAM_ID` | Team ID |
| horizon-api | `APPLE_KEY_ID` | Key ID of the environment `.p8` |
| horizon-api | `APPLE_PRIVATE_KEY` | Full content of the `.p8` |
| horizon-api | `APPLE_CLIENT_IDS` | The same ids as in Supabase, but with the bundle IDs **first** and the Services ID **last**: `com.maihuego.application.dev,com.maihuego.application.sandbox,com.maihuego.signin.dev` |
| horizon-api | `APPLE_SERVICES_ID` | `com.maihuego.signin.dev` |
| horizon-api | `AUTH_PROVIDER_TOKEN_KEYRING` | A new keyring per environment (encrypts Apple refresh tokens) |
| horizon-authenticate | `AUTH_BFF_SERVER_TOKEN` | **The same value** as in horizon-api |

> [!WARNING]
>
> The order of `APPLE_CLIENT_IDS` is not the Supabase order. Supabase lists the Services ID first;
> horizon-api expects the bundle IDs first and the Services ID last (`env-validator.ts` documents
> it that way, and the Services ID is taken from the last entry when `APPLE_SERVICES_ID` is
> missing). Always set `APPLE_SERVICES_ID` explicitly.

To generate the keyring:

```bash theme={null}
node -e 'console.log(JSON.stringify({active:"k1",keys:{k1:require("crypto").randomBytes(32).toString("base64")}}))'
```

**4. Release Train**

Actions → **Release Train** → "Use workflow from" = the alpha tag → `development` → type
`RELEASE`. The train syncs the variables, deploys, runs the migration (`auth_provider_credential`
and the `provider` and `is_private_email` columns) and starts the development EAS build.

**5. Flags**

Horizon Enterprise (development) → Capabilities → **Sync**. It creates the `authenticate`
category with `authenticate-oauth-google`, `authenticate-oauth-apple` and
`authenticate-oauth-microsoft` turned off, and deletes the old `maihuego-application-oauth-*`
keys. Turn all three on.

**6. Smoke test**

Web: e-mail sign-in on horizon-authenticate, the Apple button and the portal password banner.
App: the development build on iOS and Android.

## Step 2 · Certification

**1. rc tag**

`pnpm pr:rc` opens the `develop → release` PR; merging it creates the `-rc.N` tag.

**2. Consoles**

Repeat Apple (Services ID `com.maihuego.signin.cert` and its `.p8`), Supabase certification
(Client IDs `com.maihuego.signin.cert,com.maihuego.application.cert`) and 1Password
certification:

| App | Variable | Value |
| - | - | - |
| horizon-api | `APPLE_CLIENT_IDS` | `com.maihuego.application.cert,com.maihuego.signin.cert` |
| horizon-api | `APPLE_SERVICES_ID` | `com.maihuego.signin.cert` |

**3. Release Train and flags**

Train with the rc tag → `certification` (one approval). Then Sync and turn on the three flags.

**4. Manual tests**

With the TestFlight build and the internal APK, walk MT-01 to MT-11 of
[`authenticate/oauth/05-test-plan.md`](https://github.com/bbrandslab/bbrands-monorepo/blob/develop/docs/initiatives/authenticate/oauth/05-test-plan.md)
and record the result there. For hidden e-mail, confirm in Resend that the magic link to the relay
was delivered without a bounce.

## Step 3 · Production

**1. Stable tag**

`pnpm pr:release` opens `release → master`; merging it creates the stable tag.

**2. Consoles**

Repeat Apple (Services ID `com.maihuego.signin`), Supabase production
(`com.maihuego.signin,com.maihuego.application,com.maihuego.application.preprod`) and 1Password
production:

| App | Variable | Value |
| - | - | - |
| horizon-api | `APPLE_CLIENT_IDS` | `com.maihuego.application,com.maihuego.application.preprod,com.maihuego.signin` |
| horizon-api | `APPLE_SERVICES_ID` | `com.maihuego.signin` |

Double-check that `AUTH_BFF_SERVER_TOKEN` is the same in horizon-api and horizon-authenticate.

**3. Release Train**

Train with the stable tag → `production` (two approvals). The production EAS build is submitted to
the stores automatically.

**4. Production flags**

Sync and turn on **only** `authenticate-oauth-google` and `authenticate-oauth-apple`. Microsoft
stays off. Older app versions do not read these keys and show no provider.

**5. App Review**

In App Store Connect → App Review Information, leave the reviewer note and the demo account
credentials (from 1Password, never in the repository), then **Submit for Review**.

```text theme={null}
Sign in with Apple is offered next to Google on the first screen and on sign-in (guideline 4.8).
Registering with a provider asks for no password; a password can be created later from Home or
Settings. Account deletion is in Settings and revokes the Sign in with Apple authorization.
```

**6. Google Play**

Once Apple approves, publish on Google Play so both stores carry the same version.

**7. Mandatory release**

With the version published in **both** stores: Horizon Enterprise → MaihueGO release → each store
→ mandatory. Check with the previous version that the answer carries `update_required: true`:

```bash theme={null}
curl -s "https://api.bbrands.io/api/v3/bbrands/application/release/maihuego/check-mandatory?os=ios&version=<previous version>"
```

**8. Rotation reminder**

The Apple secret in Supabase expires after six months. Set a reminder at five months per
environment. See [Operations and maintenance](https://docs.bbrands.io/maihuego/authentication/operations.md).

## Summary

| Phase | What triggers it | Who |
| - | - | - |
| Alpha tag | Merge to `develop` | GitHub, automatic |
| Apple (capabilities and relay) | Once, before the first train | Operator |
| Development | Release Train with the alpha tag + flags | Operator |
| Certification | `pnpm pr:rc` → Release Train + MT-01 to MT-11 | Operator + 1 reviewer |
| Production | `pnpm pr:release` → Release Train + App Review | Operator + 2 reviewers |
| Mandatory release | Version published in both stores | Operator |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.