diff --git a/ushadow/mobile/.env.example b/ushadow/mobile/.env.example new file mode 100644 index 00000000..37048cce --- /dev/null +++ b/ushadow/mobile/.env.example @@ -0,0 +1,11 @@ +# Ushadow Mobile App Environment Variables +# Copy this file to .env and customize for your build +# +# Note: Variables must be prefixed with EXPO_PUBLIC_ to be accessible in the app + +# Default server URL (optional) +# If set, this will pre-fill the server URL field on first login +# Users can still change it during login +# Format: https://{your-tailscale-host} +# Example: https://blue.spangled-kettle.ts.net +EXPO_PUBLIC_DEFAULT_SERVER_URL= diff --git a/ushadow/mobile/README.md b/ushadow/mobile/README.md index b1ed8e86..abe6f19b 100644 --- a/ushadow/mobile/README.md +++ b/ushadow/mobile/README.md @@ -44,6 +44,38 @@ eas build --profile preview --platform ios # Requires Apple Developer accou --- +## Build Configuration + +### Setting a Default Server URL (Optional) + +You can pre-configure a default server URL that will be filled in automatically when users first open the app. This is useful when distributing the app to your team. + +**Option 1: Environment Variable (Recommended)** + +Create a `.env` file in the `ushadow/mobile/` directory: + +```bash +# Copy the example file +cp .env.example .env + +# Edit with your server URL +echo 'EXPO_PUBLIC_DEFAULT_SERVER_URL=https://your-server.ts.net' > .env +``` + +Then build the app normally. The URL will be embedded at build time. + +**Option 2: EAS Build Secrets** + +For EAS builds, set the environment variable in your EAS secrets: + +```bash +eas secret:create --name EXPO_PUBLIC_DEFAULT_SERVER_URL --value "https://your-server.ts.net" +``` + +**Note:** Users can always change the server URL during login, even if a default is set. The URL they use is saved for future logins. + +--- + ## Detailed Setup Instructions ### Prerequisites diff --git a/ushadow/mobile/app/_utils/authStorage.ts b/ushadow/mobile/app/_utils/authStorage.ts index d69ee18d..f881de3c 100644 --- a/ushadow/mobile/app/_utils/authStorage.ts +++ b/ushadow/mobile/app/_utils/authStorage.ts @@ -143,7 +143,10 @@ export function appendTokenToUrl(wsUrl: string, token: string): string { /** * Get the default server URL. - * Returns user-configured default if set, otherwise returns app config default. + * Priority: + * 1. User-saved default (from "Save as default" checkbox) + * 2. Build-time default from EXPO_PUBLIC_DEFAULT_SERVER_URL env var + * 3. Empty string (user must enter URL manually) */ export async function getDefaultServerUrl(): Promise { try { @@ -154,6 +157,7 @@ export async function getDefaultServerUrl(): Promise { } catch (error) { console.error('[AuthStorage] Failed to get default server URL:', error); } + // Fall back to build-time default from env var (or empty string) return AppConfig.DEFAULT_SERVER_URL; } @@ -172,7 +176,8 @@ export async function setDefaultServerUrl(url: string): Promise { } /** - * Clear the custom default server URL (revert to app config default). + * Clear the custom default server URL. + * After clearing, users will need to enter the URL manually on next login. */ export async function clearDefaultServerUrl(): Promise { try { @@ -186,7 +191,7 @@ export async function clearDefaultServerUrl(): Promise { /** * Get the effective server URL to use. - * Priority: stored API URL > custom default > app config default + * Priority: stored API URL from login > saved default server URL > empty string */ export async function getEffectiveServerUrl(): Promise { // First check if there's a stored API URL from login diff --git a/ushadow/mobile/app/components/LoginScreen.tsx b/ushadow/mobile/app/components/LoginScreen.tsx index 3ebaccc3..cf6732c0 100644 --- a/ushadow/mobile/app/components/LoginScreen.tsx +++ b/ushadow/mobile/app/components/LoginScreen.tsx @@ -25,7 +25,12 @@ import { ScrollView, } from 'react-native'; import { colors, theme, spacing, borderRadius, fontSize } from '../theme'; -import { saveAuthToken, saveApiUrl } from '../_utils/authStorage'; +import { + saveAuthToken, + saveApiUrl, + getDefaultServerUrl, + setDefaultServerUrl, +} from '../_utils/authStorage'; interface LoginScreenProps { visible: boolean; diff --git a/ushadow/mobile/app/config.ts b/ushadow/mobile/app/config.ts index d668c4f8..984140da 100644 --- a/ushadow/mobile/app/config.ts +++ b/ushadow/mobile/app/config.ts @@ -2,19 +2,27 @@ * App Configuration * * Central configuration for the Ushadow mobile app. - * The default server URL can be changed here or overridden by the user during setup. + * Configuration is read from environment variables at build time. + * + * To set a default server URL for your build: + * 1. Create a .env file in ushadow/mobile/ + * 2. Add: EXPO_PUBLIC_DEFAULT_SERVER_URL=https://your-server.ts.net + * 3. Build the app + * + * See README.md for more details. */ export const AppConfig = { /** * Default server URL. - * This is used as the initial value when the app is first installed. - * Users can change this in the login screen. + * Read from EXPO_PUBLIC_DEFAULT_SERVER_URL environment variable. + * If not set, users enter the URL manually during first login. + * Once logged in, the URL is persisted in AsyncStorage. * * Format: https://{your-tailscale-host} * Example: https://blue.spangled-kettle.ts.net */ - DEFAULT_SERVER_URL: 'https://ushadow.wolf-tawny.ts.net', + DEFAULT_SERVER_URL: process.env.EXPO_PUBLIC_DEFAULT_SERVER_URL || '', /** * App version info