Expo app shell

You build the Expo app shell with persisted auth state, guarded routes, and provider setup so later screens share a working foundation.

Ticket

Build the Expo app in app/, next to app-tests/. Set up Expo Router, the root providers, persisted token storage, and the initial customer screens. The login and signup forms remain placeholders. A test-user button lets you exercise the signed-in navigation before the real auth flow arrives.

This app is the first client of the Go API you built in Weeks 1 to 3. The provider and navigation structure gives later screens a stable place for queries and authentication. Module 2, API integration, adds the first real API calls.

Acceptance criteria

  • The Expo project lives in app/, next to app-tests/. You scaffold it with npx create-expo-app app --template blank-typescript, remove the generated App.tsx and index.ts, and set main in package.json to expo-router/entry.
  • All required libraries are installed together with npx expo install: expo-router, react-native-safe-area-context, react-native-screens, expo-linking, expo-constants, @tanstack/react-query, zustand, expo-secure-store, @react-native-async-storage/async-storage, expo-network and react-dom.
  • app/app.config.ts replaces app.json and configures the app name, slug, scheme: "zomatoprep", the expo-router and expo-secure-store plugins, and experiments.typedRoutes: true. It contains no API URL or secret.
  • app/.env.example is committed with a placeholder EXPO_PUBLIC_API_URL. app/.env.local contains EXPO_PUBLIC_API_URL=http://<your LAN IP>:8080 and is not committed. app/lib/config.ts reads process.env.EXPO_PUBLIC_API_URL, exports API_URL without a trailing slash, and throws a descriptive error when the variable is missing.
  • app/lib/tokens.ts exports Tokens with access and refresh string fields, the TokenStore interface with get() and set(tokens | null), a SecureTokenStore, and one tokenStore instance. The store keeps the pair as one JSON value under auth.tokens. Corrupt or missing stored data reads as null.
  • app/lib/auth.tsx exports AuthProvider and useAuth(). The provider reads tokenStore on mount. The hook exposes isLoading, isSignedIn, signIn(tokens) and signOut(), and throws when used outside the provider. Signing in stores the token pair before setting isSignedIn. Signing out stores null before clearing isSignedIn.
  • The root layout creates its QueryClient at module level. It nests QueryClientProvider, AuthProvider and the navigator in that order. The navigator shows an ActivityIndicator while auth is loading and does not render the Stack during that time.
  • The root Stack guards (auth) with !isSignedIn. It guards (tabs), restaurant/[id], orders/[id] and item/[id] with isSignedIn. The item route opens as a modal. Navigation between the signed-out and signed-in screens is handled by the guards, not by navigation calls in effects.
  • The auth group contains Log in and Create account screens. Log in includes a Continue as a test user button that signs in with dummy tokens. The tabs show Restaurants, Orders and Cart. The Restaurants screen displays API_URL and includes a Sign out button.
  • The restaurant route accepts a dynamic id, converts it to a number, and shows an error for anything that is not a positive integer. A valid ID of 1 displays the title Restaurant 1. Its button opens the configurator screen as a modal. The order detail, configurator, signup and unknown-route screens have their required placeholder content.
  • On a fresh install, the app briefly shows the loading indicator and then Log in. It never shows the Restaurants tab before the stored token check finishes.
  • Selecting Continue as a test user opens the tabs with Restaurants, Orders and Cart. After you kill the app from the app switcher and reopen it, you remain signed in. Selecting Sign out returns to Log in, and the Android back gesture does not bring the tabs back.
  • After npx expo start, pressing a opens the app on the Android emulator. Scanning the QR code with Expo Go opens the app on your phone.
  • While signed out, opening exp://<LAN IP>:8081/--/restaurant/1 on the emulator lands on Log in. While signed in, the same link opens the screen titled Restaurant 1, where the button opens the configurator as a modal.
  • With the backend running through make run, http://<LAN IP>:8080/healthz loads in your phone's browser.
  • Removing app/.env.local and restarting Metro shows the configuration error instead of a blank screen. After npx expo start has run once and generated .expo/types, npx tsc --noEmit passes in app/.

Constraints

  • Keep app/ at the repository root, beside app-tests/. The test configuration in app-tests/ resolves @app/* to app/lib/*.
  • Install the listed libraries in one npx expo install command. Do not use plain npm install for these packages. Installing react-dom alongside the other dependencies keeps its version aligned with react.
  • Keep TypeScript strict.
  • Keep the API URL in the public EXPO_PUBLIC_API_URL environment variable. Do not put it or any secret in app.config.ts. Remember that EXPO_PUBLIC_ values are included in the app bundle in plain text.
  • Keep the access token and refresh token in expo-secure-store, not in public configuration. Store the pair as one JSON value under auth.tokens.
  • Keep the TokenStore interface as the shared boundary for token persistence. The API client in exercise 4.7 uses the same interface.
  • Keep QueryClient outside AuthProvider and at module level. The navigator that calls useAuth() must be a child of AuthProvider.
  • Use protected routes for both auth states. Do not use effects to redirect between Log in and the tabs.
  • Use the Stack headers and tab bar for their built-in safe area handling. Screens without a header use react-native-safe-area-context, not SafeAreaView from react-native.

Design direction

Keep the app layout small enough to understand while you build it. Put configuration and token storage in lib/. Keep auth state in lib/auth.tsx. Let the root layout own the providers and the guarded Stack. Let the route groups own their respective layouts.

Think about a few trade-offs:

  • A single token-store interface keeps persistence independent from the API client. Later work can change how the API client uses tokens without changing auth state or the storage implementation.
  • A loading state avoids guessing whether a user is signed in while secure storage is still being read. Showing the Stack too early can expose the wrong screen for a frame.
  • Protected routes keep navigation state aligned with authentication state. Redirecting in effects adds another transition to coordinate and can leave unwanted screens in navigation history.

Any layout that meets the contract passes.

How to check your work

Run the commands from the repository root, except where the command explicitly changes into app/.

bash
npx create-expo-app app --template blank-typescript
bash
cd app && npx expo install expo-router react-native-safe-area-context react-native-screens expo-linking expo-constants @tanstack/react-query zustand expo-secure-store @react-native-async-storage/async-storage expo-network react-dom
bash
ipconfig getifaddr en0

Use the returned LAN IP in app/.env.local:

EXPO_PUBLIC_API_URL=http://<your LAN IP>:8080

Start Metro:

bash
cd app && npx expo start

Press a in the Expo CLI to open the Android emulator. Scan the QR code with Expo Go on your phone. Check that both devices open on Log in, then exercise test sign-in, restart, sign out, and the back gesture.

With the backend running through make run, open http://<LAN IP>:8080/healthz in your phone's browser. Test the restaurant deep link while signed out and signed in:

bash
adb shell am start -a android.intent.action.VIEW -d "exp://<LAN IP>:8081/--/restaurant/1"

Finally, run the typecheck after Metro has generated .expo/types:

bash
cd app && npx tsc --noEmit

W4B1 has no automated test assertions. When a manual check fails, start with the earliest failing check and trace it to the matching layer: project configuration, environment loading, token persistence, provider startup, or route guarding.

Finished Exercise 4.4?

Expo app foundations

4 items

  • 4.1React Native screen layoutnot completed
  • 4.2Expo Router navigationnot completed
  • 4.3Expo device networkingnot completed
  • 4.4Expo app shellnot completed

API client and authentication

Up next · Module 2 · 3 items · about 2 h 45 min

Start module 2

Implementation

Run locally

Write the code in your editor inside zomato-prep, then work through this list.

  1. Scaffold app/ next to app-tests/ and configure Expo Router.
  2. Set the LAN API URL and verify the phone can load /healthz.
  3. Add secure token storage and the auth provider.
  4. Add the guarded auth, tabs, restaurant, item and order routes.
  5. Verify emulator and Expo Go startup, sign-in persistence, sign-out and deep links.
  6. Run npx tsc --noEmit after Metro generates .expo/types.

Commands

terminal
npx create-expo-app app --template blank-typescript
terminal
cd app && npx expo install expo-router react-native-safe-area-context react-native-screens expo-linking expo-constants @tanstack/react-query zustand expo-secure-store @react-native-async-storage/async-storage expo-network react-dom
terminal
ipconfig getifaddr en0
terminal
cd app && npx expo start
terminal
cd app && npx tsc --noEmit
terminal
adb shell am start -a android.intent.action.VIEW -d "exp://<LAN IP>:8081/--/restaurant/1"

This exercise has no Go test. The commands above are the check: when each one shows what the list says, the exercise is done.