Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Tweak mobile app logout flow to suppress session expired warnings (#1325)
Leendert de Borstc180fdf5051b
diff --git a/apps/mobile-app/context/AppContext.tsx b/apps/mobile-app/context/AppContext.tsxindex 422decb76..dce21ed1f 100644--- a/apps/mobile-app/context/AppContext.tsx+++ b/apps/mobile-app/context/AppContext.tsx@@ -1,4 +1,4 @@-import React, { createContext, useContext, useMemo, useCallback, useEffect, useState } from 'react';+import React, { createContext, useContext, useMemo, useCallback, useEffect, useRef } from 'react';import { router } from 'expo-router';import { useAuth } from '@/context/AuthContext';@@ -17,7 +17,6 @@ type AppContextType = {initializeAuth: () => Promise<{ isLoggedIn: boolean; enabledAuthMethods: AuthMethod[] }>;setAuthTokens: (username: string, accessToken: string, refreshToken: string) => Promise<void>;login: () => Promise<void>;- isLoggingOut: boolean;// Auth methods from AuthContextgetEnabledAuthMethods: () => Promise<AuthMethod[]>;isBiometricsEnabled: () => Promise<boolean>;@@ -50,7 +49,7 @@ const AppContext = createContext<AppContextType | undefined>(undefined);export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {const auth = useAuth();const webApi = useWebApi();- const [isLoggingOut, setIsLoggingOut] = useState(false);+ const isLoggingOutRef = useRef(false);/*** Logout the user by revoking tokens and clearing the auth tokens from storage.@@ -58,21 +57,20 @@ export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ children*/const logout = useCallback(async (errorMessage?: string): Promise<void> => {// Prevent recursive logout calls- if (isLoggingOut) {- console.debug('Logout already in progress, ignoring duplicate call');+ if (isLoggingOutRef.current) {return;}try {- setIsLoggingOut(true);+ isLoggingOutRef.current = true;await webApi.revokeTokens();await auth.clearAuth(errorMessage);} catch (error) {console.error('Error during logout:', error);} finally {- setIsLoggingOut(false);+ isLoggingOutRef.current = false;}- }, [auth, webApi, isLoggingOut]);+ }, [auth, webApi]);/*** Subscribe to logout events from WebApiService.@@ -113,7 +111,6 @@ export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ childreninitializeAuth: auth.initializeAuth,setAuthTokens: auth.setAuthTokens,login: auth.login,- isLoggingOut,// Pass through other auth methodsgetEnabledAuthMethods: auth.getEnabledAuthMethods,isBiometricsEnabled: auth.isBiometricsEnabled,@@ -156,7 +153,6 @@ export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ childrenauth.markAutofillConfigured,auth.setReturnUrl,logout,- isLoggingOut,]);return (diff --git a/apps/mobile-app/context/AuthContext.tsx b/apps/mobile-app/context/AuthContext.tsxindex f55a42e25..93be91ffc 100644--- a/apps/mobile-app/context/AuthContext.tsx+++ b/apps/mobile-app/context/AuthContext.tsx@@ -195,6 +195,15 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children* This is called by AppContext after revoking tokens on the server.*/const clearAuth = useCallback(async (errorMessage?: string): Promise<void> => {+ console.log('Clearing auth --- attempt');+ // Clear credential identity store (password and passkey autofill metadata)+ try {+ await NativeVaultManager.removeCredentialIdentities();+ } catch (error) {+ console.error('Failed to remove credential identities:', error);+ // Non-fatal error - continue with logout+ }+// Clear from native layerawait NativeVaultManager.clearUsername();await NativeVaultManager.clearAuthTokens();@@ -206,14 +215,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ childrenawait AsyncStorage.removeItem('refreshToken');await AsyncStorage.removeItem('authMethods');- // Clear credential identity store (passkey metadata)- try {- await NativeVaultManager.removeCredentialIdentities();- } catch (error) {- console.error('Failed to remove credential identities:', error);- // Non-fatal error - continue with logout- }-dbContext?.clearDatabase();if (errorMessage) {