# The native app (/docs/starter/native-app)

```npm
npx @clubedge/create-clubedge-app my-app --framework vite --api hono --mobile expo
```

`--mobile expo` adds `apps/mobile`, a native Android and iOS app built with [Expo](https://expo.dev) SDK 58 (React 19.3, React Native 0.88) and Expo Router. Its screens are its own, not the website's pages, and it calls the same API with the same contract client, `@clubedge/contract`: through your website, or directly in a [project without a website](../cli/without-a-website.mdx). It needs CLI 0.44.0 and Starter v0.28.0.

It is not the [mobile app](./mobile-app.mdx) (`--shell capacitor`), which packages the website's own pages with Capacitor. A project can have both.

<Callout>
  Try the Starter's native app on an Android phone: download [clubedge-native-demo.apk](https://github.com/Clubedge/clubedge-starter/releases/latest/download/clubedge-native-demo.apk) from the latest Starter release and open it, allowing installs from unknown sources when Android asks. It is the app's [demo](#the-demo): you sign up and sign in for real, against a live API. Use a password you don't use elsewhere, since the demo's accounts can be deleted at any time. iPhones install apps only from the App Store or TestFlight, so there is no file for them.
</Callout>

## Choose it [#choose-it]

The native app calls an API, so `--mobile expo` needs `--api hono` or `--api fastapi`, with `--framework vite` or `--framework none`:

| Project | The app calls |
| --- | --- |
| `--framework vite` and its API | The website's address: its server forwards `/api` to the API and answers sign-in at `/api/auth`. |
| `--framework none` and an API | The API's own address. See [Without a website](../cli/without-a-website.mdx). |

Next.js and TanStack Start have no separate API for an app to call, and an API is required, so the CLI refuses the rest:

```text
Next.js has no separate API for Expo to call: choose a frontend with an API, or --mobile none.
Expo is a mobile app and calls an API: choose one with --api (fastapi, hono).
```

Interactive runs ask **Add a native mobile app?** after the API, with Expo and None, the default. In the [builder](https://starter.clubedge.live/builder?preset=api-native), the Native app row appears once an API is picked. The project's `package.json` records the choice in `"apps"`, as `"mobile": "expo"`.

A project created without it can add it later, and drop it again, with CLI 0.46.0 or newer: `pnpm clubedge add mobile expo`, or `pnpm clubedge remove mobile` ([Change a project](../cli/change-a-project.mdx#apps-installed-on-devices)).

## What you get [#what-you-get]

<Files>
  <Folder name="apps" defaultOpen>
    <Folder name="web" />
    <Folder name="api" />
    <Folder name="mobile" defaultOpen>
      <Folder name="assets" />
      <Folder name="src" defaultOpen>
        <Folder name="app" />
        <Folder name="components" />
        <Folder name="config" />
        <Folder name="lib" />
      </Folder>
      <File name="app.config.ts" />
      <File name=".env.local" />
      <File name="package.json" />
    </Folder>
  </Folder>
  <Folder name="packages" defaultOpen>
    <Folder name="contract" />
    <File name="… one package per module you chose" />
  </Folder>
</Files>

- **`apps/mobile`**: the app, package `@clubedge/mobile-app`. Its screens are routes under `src/app` (Expo Router), and it calls the API only through `src/lib/api.ts`, the contract client. `app.config.ts` takes the app's name, id, and address scheme from `src/config/site.json`, and its icon, Android's adaptive icon, and its splash screen from `assets/`. `.env.local` holds `EXPO_PUBLIC_API_URL`, the address the app calls.
- **`android/` and `ios/`** are generated from `app.config.ts` whenever the app is built (`expo prebuild`), so they aren't committed, and an upgrade only changes the app's TypeScript and config. Change `app.config.ts`, never those folders.
- **`apps/web`** is the React + Vite website. A project without a website has none.

### The screens [#the-screens]

- **Sign-in, sign-up, and password reset.**
- **The dashboard:** the signed-in account, the API's health, and the app's version, refreshed when you pull it down. It also says when an [update](#updates) is available.
- **Settings:** the display name, the password, signing out, and deleting the account, which the App Store requires of apps that let people sign up.

With `--auth none`, the app has no sign-in and no settings: only the dashboard.

## Requirements [#requirements]

The app runs as a development build, not in Expo Go, the store app that runs projects without building them: Expo Go doesn't support SDK 58 yet.

- [Android Studio](https://developer.android.com/studio), for Android.
- A Mac with [Xcode](https://developer.apple.com/xcode/), for iOS.

Expo's [environment setup](https://docs.expo.dev/get-started/set-up-your-environment/) has the details.

## Set it up [#set-it-up]

<Steps>
<Step>

### Set the app's id [#set-the-apps-id]

In `apps/mobile/app.config.ts`, replace the generated `com.example.<project>` with a reverse-domain id you own, such as `com.yourcompany.app`. It becomes permanent once a store lists the app, so set it before the first release build. The app's name and its address scheme come from `apps/mobile/src/config/site.json`.

</Step>
<Step>

### Start the API [#start-the-api]

```sh
pnpm dev
```

It starts the website and the API, or the API alone in a project without a website. Left blank in development, `EXPO_PUBLIC_API_URL` means this computer's dev server: the app calls `http://10.0.2.2:3000` from the Android emulator and `http://localhost:3000` from the iOS simulator, or port 3001 without a website, the API's. On a phone, set it to your computer's address on the same network, with port 3001 without a website:

```dotenv title="apps/mobile/.env.local"
EXPO_PUBLIC_API_URL=http://192.168.1.20:3000
```

With Supabase Auth, set `EXPO_PUBLIC_SUPABASE_URL` and `EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY` there too ([Sign-in](#sign-in)).

</Step>
<Step>

### Build and run it [#build-and-run-it]

```sh
pnpm --filter @clubedge/mobile-app android   # or ios, on a Mac
```

The first run generates the native project, builds the app, installs it on a running emulator or a connected phone, and starts Expo's dev server, which reloads the app as you change it. Later, `pnpm --filter @clubedge/mobile-app start` starts the dev server for the build already installed. Build again after adding a package with native code.

</Step>
</Steps>

## Commands [#commands]

| Command | What it does |
| --- | --- |
| `pnpm --filter @clubedge/mobile-app android` | Build the app, install it on the Android emulator or a phone, and start Expo's dev server. The first run generates `apps/mobile/android`. |
| `pnpm --filter @clubedge/mobile-app ios` | The same for iOS, on a Mac. The first run generates `apps/mobile/ios`. |
| `pnpm --filter @clubedge/mobile-app start` | Start the dev server for the app already installed. |
| `pnpm --filter @clubedge/mobile-app prebuild` | Generate `android/` and `ios/` from `app.config.ts`, to build a release in Android Studio or Xcode. |

## How it works with the API [#how-it-works-with-the-api]

- **Its address.** `EXPO_PUBLIC_API_URL` is built into the app. With a website, it is the website's address: its server forwards `/api` to the API and answers sign-in at `/api/auth`. Without one, it is the API's, which answers both.
- **No browser origin.** The app sends none, so the CORS settings don't apply to it.
- **Its session** stays on the device: the app stays signed in offline, and signing out forgets the session even when the server can't be reached.
- **No payments.** App stores require their own in-app purchases for digital goods, so the app has no billing: subscriptions stay on the website.

### Sign-in [#sign-in]

<Tabs items={['Better Auth', 'Supabase Auth']} groupId="auth" persist>
  <Tab value="Better Auth">
    Better Auth runs in the website's server, or in the API without a website. Its Expo plugin keeps the session cookie in the device's secure storage and sends it with the app's calls. The server trusts the app's address scheme, which the app sends when it signs in. Both make the scheme from their site config's `serviceId`, such as `my-product://`, so keep `apps/mobile/src/config/site.json` and the server's copy (`apps/web/src/config/site.json`, or `apps/api/src/config/site.json` without a website) on the same `serviceId`.
  </Tab>
  <Tab value="Supabase Auth">
    Supabase keeps the app's session in the app's storage on the device, and the app sends its access token to the API, as the website does. Set `EXPO_PUBLIC_SUPABASE_URL` and `EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY` in `apps/mobile/.env.local` to the website's Supabase settings, or the API's without a website, before you build the app. No secret key belongs there.
  </Tab>
</Tabs>

Firebase Authentication and Appwrite aren't in the native app, so the CLI refuses them with `--mobile expo`:

```text
Expo does not implement Firebase Authentication (--auth firebase). It implements: supabase, better-auth, none.
```

### Emailed links [#emailed-links]

- **With a website,** confirmation and password reset links open the website. After confirming an address or setting a new password, sign in again in the app.
- **Without one,** they open the app through its address scheme: confirming a new account opens its sign-in screen, and a password reset link opens its reset screen, which sets the new password. With Better Auth, this needs an [email module](./modules/email.mdx). With Supabase Auth, add the scheme to the Redirect URLs in Supabase's URL configuration, such as `my-product://**`. The local Supabase stack (`--infra supabase`) reads them from `additional_redirect_urls` in `supabase/config.toml`: add it there too, and restart the stack.

## Updates [#updates]

An installed app keeps the version it shipped with, often for months. It asks the API's `GET /api/app-version` which versions the API serves, and compares its own, `version` in `app.json` (in `app.config.ts` before Starter v0.30.0). It asks when it starts, and from Starter v0.29.0 also when it comes back to the foreground (at most every 15 minutes) and whenever the API refuses its version ([Apps the API refuses](../cli/frontend-and-api.mdx#apps-the-api-refuses)):

- Below `APP_MINIMUM_VERSION`, it shows only **Update required**, with an **Update** button that opens `APP_UPDATE_URL`. From Starter v0.29.0, the app remembers it, so it holds when the app next starts offline, until it is updated.
- Below `APP_NEXT_MINIMUM_VERSION` (Starter v0.29.0 or newer), the dashboard says the date the app stops working, and **Not now** hides it until the next day.
- Below `APP_LATEST_VERSION`, the dashboard says an update is available. From Starter v0.29.0, **Not now** hides it until a newer version is out.
- When the API can't be reached, nothing new shows: a remembered **Update required** still holds, and otherwise the app carries on.

Set the versions on the API, in `apps/api/.env.local` or the API's environment in production: see [Apps installed on phones](../cli/frontend-and-api.mdx#apps-installed-on-phones). Give `version` as `MAJOR.MINOR.PATCH`, such as `1.4.0`, and raise it with each release: see [Store releases](#store-releases).

Installed apps also keep calling the API contract they shipped with, so CI fails a pull request that breaks it: see [Keep the contract compatible](../cli/frontend-and-api.mdx#keep-the-contract-compatible).

## Store releases [#store-releases]

From Starter v0.30.0, the app's version, which the stores show and the update notice compares, is `version` in `apps/mobile/app.json`. `app.config.ts` makes both stores' build number from it, so a new version is a new build: 1.4.2 is build 1004002. A project from Starter v0.29.0 or earlier kept its version in `app.config.ts`: after upgrading, keep the Starter's `app.config.ts`, and carry your version over with `set-version`. Set a newer one for each release:

```sh
pnpm --filter @clubedge/mobile-app set-version 1.5.0
```

The app builds with [EAS Build](https://docs.expo.dev/build/introduction/), in Expo's cloud, with the profiles in `apps/mobile/eas.json`:

| Profile | Builds |
| --- | --- |
| `development` | A development build, with Expo's dev client, to install on your devices |
| `preview` | A release build to share, an APK on Android |
| `production` | The stores' build |

<Steps>
<Step>
Link the app to an Expo project, from `apps/mobile`: `pnpm dlx eas-cli@latest init`, which writes the project's id into `app.json`.
</Step>
<Step>
Give each EAS environment the address the app calls, the website's or, without a website, the API's. It is built into the app, and `.env.local` stays on your computer:

```sh
pnpm dlx eas-cli@latest env:create --environment production --name EXPO_PUBLIC_API_URL --value https://app.example.com --visibility plaintext
```
</Step>
<Step>
Run a first build interactively, `pnpm dlx eas-cli@latest build --profile production`. It sets up the signing credentials EAS then keeps: Android's upload key, and on iOS, with your Apple Developer account, a distribution certificate and a provisioning profile.
</Step>
</Steps>

From then on, the **Native app release** workflow (`.github/workflows/expo-release.yml`, run from the Actions tab) queues builds with an `EXPO_TOKEN` repository secret (expo.dev, Account settings, Access tokens), for both stores or one, and submits production builds to the stores when asked. Once the stores publish a release, set the API's `APP_LATEST_VERSION` to it ([Updates](#updates)).

To build on your computer instead, run `pnpm --filter @clubedge/mobile-app prebuild`, then Android Studio or Xcode, with your own signing key and `EXPO_PUBLIC_API_URL` in `apps/mobile/.env.local`.

## Push notifications and over-the-air updates [#push-notifications-and-over-the-air-updates]

Two modules are for the native app (Starter v0.30.0 or newer):

- [Push notifications](./modules/push.mdx) (`--push expo` or `--push native`): a Notifications switch and a test notification in Settings, sent through Expo's push service or straight through FCM and APNs.
- [Over-the-air updates](./modules/ota.mdx) (`--ota eas`): changes to the app's JavaScript reach installed apps with EAS Update, without a store release.

## The demo [#the-demo]

Each Starter release from v0.28.0 attaches the Starter's own native app for Android, [clubedge-native-demo.apk](https://github.com/Clubedge/clubedge-starter/releases/latest/download/clubedge-native-demo.apk). It is built from a project without a website, with Hono and Better Auth, and the release deploys that project's API to Render's free plan, so the app's sign-up, sign-in, and settings run against a real server and database. After a quiet spell, the API's first answer takes about a minute while Render wakes it.

## CI [#ci]

The project's CI has an `expo` job. It checks the app's packages against its Expo SDK (`expo install --check`), bundles its JavaScript for Android and iOS (`expo export`), and builds a release APK, signed with a debug key, which it keeps for 7 days as the run's **android-release** artifact, to install on a device. Set an `EXPO_PUBLIC_API_URL` repository variable so that the APK calls your website, or your API without one; without it, the APK calls `https://example.com`.

`pnpm audit` skips two advisories in Expo's development CLI, which builds and serves the app but isn't part of it: node-forge's, which has no fixed release, and zod 3's. Projects without the native app don't skip them.

## Limits [#limits]

- It needs a separate API: React + Vite with Hono or FastAPI, or an API alone. Next.js and TanStack Start have none for it to call.
- Sign-in is Better Auth, Supabase Auth, or none.
- No in-app payments: subscriptions stay on the website.
- The stores' accounts, listings, and review are yours. The builds, their signing, and their submission are set up: see [Store releases](#store-releases).

## When the app can't reach the API [#when-the-app-cant-reach-the-api]

The dashboard's API card says which address the app couldn't reach. Check `EXPO_PUBLIC_API_URL` in `apps/mobile/.env.local`: a release build needs the website's `https://` address, or the API's without a website, and a phone in development your computer's address on the same network, with port 3001 without a website. The value is built into the app, so build it again after changing it.
