#!/usr/bin/env bash
# mobile-up-noauth.sh — start the Expo mobile app with AUTH_BYPASS.
#
# Requires the backend to also be running in bypass mode:
#   ./dev-up-noauth.sh
#
# Real device: replace localhost with your LAN IP in EXPO_PUBLIC_API_BASE_URL
# e.g.: EXPO_PUBLIC_API_BASE_URL=http://192.168.1.x:8000 ./mobile-up-noauth.sh

set -euo pipefail
cd "$(dirname "$0")/src/mobile"

# Install dependencies if node_modules is missing or package.json is newer
if [ ! -d node_modules ] || [ package.json -nt node_modules ]; then
  echo "  Installing dependencies…"
  npm install
fi

export EXPO_PUBLIC_AUTH_BYPASS=true
export EXPO_PUBLIC_API_BASE_URL="${EXPO_PUBLIC_API_BASE_URL:-http://localhost:8000}"
export EXPO_PUBLIC_APP_URL="${EXPO_PUBLIC_APP_URL:-http://localhost:5173}"

echo ""
echo "  Continuum Mobile — bypass mode"
echo "  API   ${EXPO_PUBLIC_API_BASE_URL}"
echo "  Auth  BYPASSED"
echo "  Press i → iOS simulator  |  a → Android emulator  |  s → Expo Go"
echo ""

# --clear flushes Metro's cache. EXPO_PUBLIC_AUTH_BYPASS is inlined into the
# bundle at build time, so without this a stale bundle keeps the old value —
# the app shows the Zitadel login (and hides the dev banner) even though
# EXPO_PUBLIC_AUTH_BYPASS=true here. Clearing guarantees the flag re-inlines.
npx expo start --clear "$@"
