Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ushadow/mobile/.env.example
Original file line number Diff line number Diff line change
@@ -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=
32 changes: 32 additions & 0 deletions ushadow/mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions ushadow/mobile/app/_utils/authStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
try {
Expand All @@ -154,6 +157,7 @@ export async function getDefaultServerUrl(): Promise<string> {
} 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;
}

Expand All @@ -172,7 +176,8 @@ export async function setDefaultServerUrl(url: string): Promise<void> {
}

/**
* 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<void> {
try {
Expand All @@ -186,7 +191,7 @@ export async function clearDefaultServerUrl(): Promise<void> {

/**
* 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<string> {
// First check if there's a stored API URL from login
Expand Down
7 changes: 6 additions & 1 deletion ushadow/mobile/app/components/LoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 12 additions & 4 deletions ushadow/mobile/app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down