Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Show API url in settings page, refactor login api url rendering (#957)

Leendert de Borstbba16e6e1489
diff --git a/apps/mobile-app/app/(tabs)/settings/index.tsx b/apps/mobile-app/app/(tabs)/settings/index.tsx
index 819dc4438..4099706f3 100644
--- a/apps/mobile-app/app/(tabs)/settings/index.tsx
+++ b/apps/mobile-app/app/(tabs)/settings/index.tsx
@@ -3,6 +3,7 @@ import { router, useFocusEffect } from 'expo-router';
import { useRef, useState, useCallback } from 'react';
import { StyleSheet, View, ScrollView, TouchableOpacity, Animated, Platform, Alert } from 'react-native';
+import { useApiUrl } from '@/utils/ApiUrlUtility';
import { AppInfo } from '@/utils/AppInfo';
import { useColors } from '@/hooks/useColorScheme';
@@ -25,6 +26,7 @@ export default function SettingsScreen() : React.ReactNode {
const colors = useColors();
const { getAuthMethodDisplay, shouldShowAutofillReminder } = useAuth();
const { getAutoLockTimeout } = useAuth();
+ const { loadApiUrl, getDisplayUrl } = useApiUrl();
const scrollY = useRef(new Animated.Value(0)).current;
const scrollViewRef = useRef<ScrollView>(null);
const [autoLockDisplay, setAutoLockDisplay] = useState<string>('');
@@ -73,12 +75,12 @@ export default function SettingsScreen() : React.ReactNode {
* Load all settings data.
*/
const loadData = async () : Promise<void> => {
- await Promise.all([loadAutoLockDisplay(), loadAuthMethodDisplay()]);
+ await Promise.all([loadAutoLockDisplay(), loadAuthMethodDisplay(), loadApiUrl()]);
setIsFirstLoad(false);
};
loadData();
- }, [getAutoLockTimeout, getAuthMethodDisplay, setIsFirstLoad])
+ }, [getAutoLockTimeout, getAuthMethodDisplay, setIsFirstLoad, loadApiUrl])
);
/**
@@ -133,6 +135,14 @@ export default function SettingsScreen() : React.ReactNode {
};
const styles = StyleSheet.create({
+ connectionStatus: {
+ alignItems: 'center',
+ },
+ connectionStatusText: {
+ color: colors.textMuted,
+ fontSize: 14,
+ textAlign: 'center',
+ },
scrollContent: {
paddingBottom: 40,
paddingTop: Platform.OS === 'ios' ? 42 : 16,
@@ -344,7 +354,7 @@ export default function SettingsScreen() : React.ReactNode {
</View>
<View style={styles.versionContainer}>
- <ThemedText style={styles.versionText}>App version {AppInfo.VERSION}</ThemedText>
+ <ThemedText style={styles.versionText}>App version {AppInfo.VERSION} ({getDisplayUrl()})</ThemedText>
</View>
</Animated.ScrollView>
</ThemedContainer>
diff --git a/apps/mobile-app/app/login.tsx b/apps/mobile-app/app/login.tsx
index 15ad2af45..778ca2ae2 100644
--- a/apps/mobile-app/app/login.tsx
+++ b/apps/mobile-app/app/login.tsx
@@ -1,14 +1,13 @@
import { Buffer } from 'buffer';
import { MaterialIcons } from '@expo/vector-icons';
-import AsyncStorage from '@react-native-async-storage/async-storage';
import { useFocusEffect } from '@react-navigation/native';
import { LinearGradient } from 'expo-linear-gradient';
import { router } from 'expo-router';
import React, { useState, useEffect } from 'react';
import { StyleSheet, View, Text, SafeAreaView, TextInput, TouchableOpacity, ActivityIndicator, Animated, ScrollView, KeyboardAvoidingView, Platform, Dimensions, Alert } from 'react-native';
-import { AppInfo } from '@/utils/AppInfo';
+import { useApiUrl } from '@/utils/ApiUrlUtility';
import ConversionUtility from '@/utils/ConversionUtility';
import type { EncryptionKeyDerivationParams } from '@/utils/dist/shared/models/metadata';
import type { LoginResponse, VaultResponse } from '@/utils/dist/shared/models/webapi';
@@ -33,19 +32,7 @@ import { useWebApi } from '@/context/WebApiContext';
export default function LoginScreen() : React.ReactNode {
const colors = useColors();
const [fadeAnim] = useState(new Animated.Value(0));
- const [apiUrl, setApiUrl] = useState<string>(AppInfo.DEFAULT_API_URL);
-
- /**
- * Load the API URL.
- */
- const loadApiUrl = async () : Promise<void> => {
- const storedUrl = await AsyncStorage.getItem('apiUrl');
- if (storedUrl && storedUrl.length > 0) {
- setApiUrl(storedUrl);
- } else {
- setApiUrl(AppInfo.DEFAULT_API_URL);
- }
- };
+ const { loadApiUrl, getDisplayUrl } = useApiUrl();
useEffect(() => {
Animated.timing(fadeAnim, {
@@ -54,21 +41,13 @@ export default function LoginScreen() : React.ReactNode {
useNativeDriver: true,
}).start();
loadApiUrl();
- }, [fadeAnim]);
+ }, [fadeAnim, loadApiUrl]);
// Update URL when returning from settings
useFocusEffect(() => {
loadApiUrl();
});
- /**
- * Get the display URL.
- */
- const getDisplayUrl = () : string => {
- const cleanUrl = apiUrl.replace('https://', '').replace('/api', '');
- return cleanUrl === 'app.aliasvault.net' ? 'aliasvault.net' : cleanUrl;
- };
-
const [credentials, setCredentials] = useState({
username: '',
password: '',
diff --git a/apps/mobile-app/utils/ApiUrlUtility.ts b/apps/mobile-app/utils/ApiUrlUtility.ts
new file mode 100644
index 000000000..37ebc78ab
--- /dev/null
+++ b/apps/mobile-app/utils/ApiUrlUtility.ts
@@ -0,0 +1,45 @@
+import AsyncStorage from '@react-native-async-storage/async-storage';
+import { useState } from 'react';
+
+import { AppInfo } from '@/utils/AppInfo';
+
+/**
+ * Hook to manage API URL state and display logic.
+ * @returns Object containing apiUrl state and utility functions
+ */
+export const useApiUrl = (): {
+ apiUrl: string;
+ setApiUrl: (url: string) => void;
+ loadApiUrl: () => Promise<void>;
+ getDisplayUrl: () => string;
+} => {
+ const [apiUrl, setApiUrl] = useState<string>(AppInfo.DEFAULT_API_URL);
+
+ /**
+ * Load the API URL from storage.
+ */
+ const loadApiUrl = async (): Promise<void> => {
+ const storedUrl = await AsyncStorage.getItem('apiUrl');
+ if (storedUrl && storedUrl.length > 0) {
+ setApiUrl(storedUrl);
+ } else {
+ setApiUrl(AppInfo.DEFAULT_API_URL);
+ }
+ };
+
+ /**
+ * Get the display URL for UI presentation.
+ * @returns Formatted display URL
+ */
+ const getDisplayUrl = (): string => {
+ const cleanUrl = apiUrl.replace('https://', '').replace('http://', '').replace(':443', '').replace('/api', '');
+ return cleanUrl === 'app.aliasvault.net' ? 'aliasvault.net' : cleanUrl;
+ };
+
+ return {
+ apiUrl,
+ setApiUrl,
+ loadApiUrl,
+ getDisplayUrl,
+ };
+};