Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Create separate add-edit page instead of modal for better deep link compatibility (#771)
Leendert de Borst94c4783c0189
diff --git a/apps/mobile-app/app/(tabs)/credentials/_layout.tsx b/apps/mobile-app/app/(tabs)/credentials/_layout.tsxindex c3ba056f0..9094461af 100644--- a/apps/mobile-app/app/(tabs)/credentials/_layout.tsx+++ b/apps/mobile-app/app/(tabs)/credentials/_layout.tsx@@ -25,6 +25,15 @@ export default function CredentialsLayout(): React.ReactNode {...defaultHeaderOptions,}}/>+ <Stack.Screen+ name="add-edit-page"+ options={{+ title: 'Add Credential',+ headerShown: true,+ gestureEnabled: true,+ ...defaultHeaderOptions,+ }}+ /><Stack.Screenname="autofill-credential-created"options={{diff --git a/apps/mobile-app/app/(tabs)/credentials/add-edit-page.tsx b/apps/mobile-app/app/(tabs)/credentials/add-edit-page.tsxnew file mode 100644index 000000000..af7068739--- /dev/null+++ b/apps/mobile-app/app/(tabs)/credentials/add-edit-page.tsx@@ -0,0 +1,32 @@+import React from 'react';+import { View, StyleSheet } from 'react-native';++import AddEditCredentialScreen from './add-edit';++/**+ * AddEditPageScreen Component+ *+ * This screen component displays add/edit credential details as a page+ * instead of a modal. This is because when deeplinking to the add/edit+ * credential screen, the modal presentation gives issues when the vault+ * is locked due to time-out and can freeze the screen. Using a normal+ * page presentation style works around this issue.+ *+ * This component is only used by deep-linking, all normal app links+ * use the normal add-edit.tsx modal component.+ */+export default function AddEditPageScreen(): React.ReactNode {+ return (+ <View style={styles.container}>+ <AddEditCredentialScreen />+ </View>+ );+}++const styles = StyleSheet.create({+ container: {+ flex: 1,+ paddingBottom: 60,+ paddingTop: 40,+ },+});diff --git a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsxindex 50e4f7b9b..6474960a5 100644--- a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx+++ b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx@@ -103,12 +103,6 @@ export default function AddEditCredentialScreen() : React.ReactNode {const serviceName = extractServiceNameFromUrl(decodedUrl);setValue('ServiceUrl', decodedUrl);setValue('ServiceName', serviceName);-- // Focus and select the service name field- setTimeout(() => {- serviceNameRef.current?.focus();- serviceNameRef.current?.selectAll();- }, 100);}}, [id, isEditMode, serviceUrl, loadExistingCredential, setValue]);diff --git a/apps/mobile-app/app/_layout.tsx b/apps/mobile-app/app/_layout.tsxindex 3cb2839a7..61b205ce6 100644--- a/apps/mobile-app/app/_layout.tsx+++ b/apps/mobile-app/app/_layout.tsx@@ -60,7 +60,6 @@ function RootLayoutNav() : React.ReactNode {return;}- // Perform initial vault syncawait syncVault({initialSync: true,/**@@ -86,15 +85,20 @@ function RootLayoutNav() : React.ReactNode {await new Promise(resolve => setTimeout(resolve, 1000));setStatus('Decrypting vault');await new Promise(resolve => setTimeout(resolve, 1000));+// The vault is successfully unlocked, so we let the native code handle the default routing.- } else {- setRedirectTarget('/unlock');+ setBootComplete(true);+ return;}++ setRedirectTarget('/unlock');+ setBootComplete(true);+ return;} else {setRedirectTarget('/unlock');+ setBootComplete(true);+ return;}-- setBootComplete(true);};initialize();@@ -102,33 +106,36 @@ function RootLayoutNav() : React.ReactNode {useEffect(() => {/**- * Simulate stack navigation.- */- function simulateStackNavigation(from: string, to: string) : void {- router.replace(from as Href);- setTimeout(() => {- router.push(to as Href);- }, 0);- }-- /**- * Redirect to the target if we have one, otherwise check for a deep link and simulate stack navigation.+ * Redirect to a explicit target page if we have one (in case of non-happy path).+ * Otherwise check for a deep link and simulate stack navigation.+ * If neither is present, we let the router redirect us to the default route.*/const redirect = async () : Promise<void> => {- if (bootComplete && redirectTarget) {+ if (!bootComplete) {+ return;+ }++ if (redirectTarget) {// If we have an explicit redirect target, we navigate to it. This overrides potential deep link handling.router.replace(redirectTarget as Href);- } else if (bootComplete) {+ } else {+ // Check if we have an initial URL to handle (deep link from most likely the autofill extension).const initialUrl = await Linking.getInitialURL();if (initialUrl) {/**- * Check for certain deep link routes, and if found, ensure we simulate the stack navigation+ * Check for certain supported deep link routes, and if found, ensure we simulate the stack navigation* as otherwise the "back" button for navigation will not work as expected.*/const path = initialUrl.replace('net.aliasvault.app://', '');const isDetailRoute = path.includes('credentials/');if (isDetailRoute) {- simulateStackNavigation('/(tabs)/credentials', path);+ // First go to the credentials tab.+ router.replace('/(tabs)/credentials');++ // Then push the target route inside the credentials tab.+ setTimeout(() => {+ router.push(path as Href);+ }, 0);}}}diff --git a/apps/mobile-app/app/reinitialize.tsx b/apps/mobile-app/app/reinitialize.tsxindex 0549869b7..083586943 100644--- a/apps/mobile-app/app/reinitialize.tsx+++ b/apps/mobile-app/app/reinitialize.tsx@@ -1,5 +1,5 @@import { useEffect, useRef, useState } from 'react';-import { router } from 'expo-router';+import { Href, router } from 'expo-router';import { StyleSheet, View } from 'react-native';import NativeVaultManager from '@/specs/NativeVaultManager';@@ -30,6 +30,49 @@ export default function ReinitializeScreen() : React.ReactNode {hasInitialized.current = true;+ /**+ * Redirect to the return URL.+ */+ function redirectToReturnUrl() : void {+ /**+ * Simulate stack navigation.+ */+ function simulateStackNavigation(from: string, to: string) : void {+ router.replace(from as Href);+ setTimeout(() => {+ router.push(to as Href);+ }, 0);+ }++ if (authContext.returnUrl?.path) {+ // Type assertion needed due to router type limitations+ const path = authContext.returnUrl.path as '/';+ const isDetailRoute = path.includes('credentials/');+ if (isDetailRoute) {+ // If there is a "serviceUrl" or "id" param from the return URL, use it.+ const params = authContext.returnUrl.params as Record<string, string>;++ if (params.serviceUrl) {+ simulateStackNavigation('/(tabs)/credentials', path + '?serviceUrl=' + params.serviceUrl);+ } else if (params.id) {+ simulateStackNavigation('/(tabs)/credentials', path + '?id=' + params.id);+ } else {+ simulateStackNavigation('/(tabs)/credentials', path);+ }+ } else {+ router.replace({+ pathname: path,+ params: authContext.returnUrl.params as Record<string, string>+ });+ }+ // Clear the return URL after using it+ authContext.setReturnUrl(null);+ } else {+ // If there is no return URL, navigate to the credentials tab as default entry page.+ router.replace('/(tabs)/credentials');+ }+ }+/*** Initialize the app.*/@@ -71,8 +114,8 @@ export default function ReinitializeScreen() : React.ReactNode {setStatus('Decrypting vault');await new Promise(resolve => setTimeout(resolve, 1000));- // Navigate to credentials- router.replace('/(tabs)/credentials');+ // Vault is successfully unlocked, redirect to the stored return URL (if any) or default entry page.+ redirectToReturnUrl();return;} else {@@ -112,6 +155,7 @@ export default function ReinitializeScreen() : React.ReactNode {justifyContent: 'center',},message: {+ marginTop: 5,textAlign: 'center',},messageContainer: {diff --git a/apps/mobile-app/context/AuthContext.tsx b/apps/mobile-app/context/AuthContext.tsxindex 5358b92be..229b73cd6 100644--- a/apps/mobile-app/context/AuthContext.tsx+++ b/apps/mobile-app/context/AuthContext.tsx@@ -1,7 +1,7 @@import React, { createContext, useContext, useState, useEffect, useMemo, useCallback, useRef } from 'react';import AsyncStorage from '@react-native-async-storage/async-storage';import { AppState, Platform } from 'react-native';-import { router, usePathname } from 'expo-router';+import { router, useGlobalSearchParams, usePathname } from 'expo-router';import { NavigationContainerRef, ParamListBase } from '@react-navigation/native';import * as LocalAuthentication from 'expo-local-authentication';@@ -33,6 +33,9 @@ type AuthContextType = {// iOS Autofill methodsshouldShowIosAutofillReminder: boolean;markIosAutofillConfigured: () => Promise<void>;+ // Return URL methods+ returnUrl: { path: string; params?: object } | null;+ setReturnUrl: (url: { path: string; params?: object } | null) => void;}const IOS_AUTOFILL_CONFIGURED_KEY = 'ios_autofill_configured';@@ -51,9 +54,16 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ childrenconst [username, setUsername] = useState<string | null>(null);const [globalMessage, setGlobalMessage] = useState<string | null>(null);const [shouldShowIosAutofillReminder, setShouldShowIosAutofillReminder] = useState(false);+ const [returnUrl, setReturnUrl] = useState<{ path: string; params?: object } | null>(null);const appState = useRef(AppState.currentState);const dbContext = useDb();const pathname = usePathname();+ const params = useGlobalSearchParams();+ const lastRouteRef = useRef<{ path: string, params?: object }>({ path: pathname, params });++ useEffect(() => {+ lastRouteRef.current = { path: pathname, params };+ }, [pathname, params]);/*** Get enabled auth methods from the native module@@ -257,6 +267,15 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children// Check if vault is unlocked.const isUnlocked = await isVaultUnlocked();if (!isUnlocked) {+ // Get current full URL including query params+ const currentRoute = lastRouteRef.current;+ if (currentRoute?.path) {+ setReturnUrl({+ path: currentRoute.path,+ params: currentRoute.params+ });+ }+// Database connection failed, navigate to reinitialize flowrouter.replace('/reinitialize');}@@ -320,7 +339,10 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children// iOS Autofill methodsshouldShowIosAutofillReminder,markIosAutofillConfigured,- }), [isLoggedIn, isInitialized, username, globalMessage, getEnabledAuthMethods, setAuthTokens, login, logout, clearGlobalMessage, initializeAuth, setAuthMethods, getAuthMethodDisplay, isFaceIDEnabled, getAutoLockTimeout, setAutoLockTimeout, getBiometricDisplayName, shouldShowIosAutofillReminder, markIosAutofillConfigured]);+ // Return URL methods+ returnUrl,+ setReturnUrl,+ }), [isLoggedIn, isInitialized, username, globalMessage, getEnabledAuthMethods, setAuthTokens, login, logout, clearGlobalMessage, initializeAuth, setAuthMethods, getAuthMethodDisplay, isFaceIDEnabled, getAutoLockTimeout, setAutoLockTimeout, getBiometricDisplayName, shouldShowIosAutofillReminder, markIosAutofillConfigured, returnUrl]);return (<AuthContext.Provider value={contextValue}>diff --git a/apps/mobile-app/ios/VaultUI/Components/CredentialCardView.swift b/apps/mobile-app/ios/VaultUI/Components/CredentialCardView.swiftindex 04594e6ef..c29ce9e45 100644--- a/apps/mobile-app/ios/VaultUI/Components/CredentialCardView.swift+++ b/apps/mobile-app/ios/VaultUI/Components/CredentialCardView.swift@@ -82,7 +82,7 @@ public struct CredentialCard: View {})Button(action: {- if let url = URL(string: "aliasvault://credentials/add-edit?id=\(credential.id.uuidString)") {+ if let url = URL(string: "aliasvault://credentials/add-edit-page?id=\(credential.id.uuidString)") {UIApplication.shared.open(url)}}, label: {diff --git a/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift b/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swiftindex b3600c15e..e145d6167 100644--- a/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift+++ b/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift@@ -54,7 +54,7 @@ public struct CredentialProviderView: View {if !viewModel.isChoosingTextToInsert {VStack(spacing: 12) {Button(action: {- var urlString = "net.aliasvault.app://credentials/add-edit"+ var urlString = "net.aliasvault.app://credentials/add-edit-page"if let serviceUrl = viewModel.serviceUrl {let encodedUrl = serviceUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""urlString += "?serviceUrl=\(encodedUrl)"@@ -108,7 +108,7 @@ public struct CredentialProviderView: View {ToolbarItem(placement: .navigationBarTrailing) {HStack {Button(action: {- var urlString = "net.aliasvault.app://credentials/add-edit"+ var urlString = "net.aliasvault.app://credentials/add-edit-page"if let serviceUrl = viewModel.serviceUrl {let encodedUrl = serviceUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""urlString += "?serviceUrl=\(encodedUrl)"