Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Prevent logout loop (#1274)
Leendert de Borst2f8bc97a5a37
diff --git a/apps/browser-extension/src/entrypoints/popup/context/AppContext.tsx b/apps/browser-extension/src/entrypoints/popup/context/AppContext.tsxindex 2845ed368..61a94d1f7 100644--- a/apps/browser-extension/src/entrypoints/popup/context/AppContext.tsx+++ b/apps/browser-extension/src/entrypoints/popup/context/AppContext.tsx@@ -15,6 +15,7 @@ type AppContextType = {setAuthTokens: (username: string, accessToken: string, refreshToken: string) => Promise<void>;globalMessage: string | null;clearGlobalMessage: () => void;+ isLoggingOut: boolean;}const AppContext = createContext<AppContextType | undefined>(undefined);@@ -26,15 +27,31 @@ export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ childrenconst auth = useAuth();const webApi = useWebApi();const [isLoggedIn, setIsLoggedIn] = useState(false);+ const [isLoggingOut, setIsLoggingOut] = useState(false);const { t } = useTranslation();/*** Logout the user by revoking tokens and clearing the auth tokens from storage.+ * Prevents recursive logout calls by tracking logout state.*/const logout = useCallback(async (errorMessage?: string): Promise<void> => {- await webApi.revokeTokens();- await auth.clearAuth(errorMessage);- }, [auth, webApi]);+ // Prevent recursive logout calls+ if (isLoggingOut) {+ console.debug('Logout already in progress, ignoring duplicate call');+ return;+ }++ try {+ setIsLoggingOut(true);+ await webApi.revokeTokens();+ await auth.clearAuth(errorMessage);+ setIsLoggedIn(false);+ } catch (error) {+ console.error('Error during logout:', error);+ } finally {+ setIsLoggingOut(false);+ }+ }, [auth, webApi, isLoggingOut]);/*** Initialize the authentication state.@@ -76,6 +93,7 @@ export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ childrensetAuthTokens: auth.setAuthTokens,clearGlobalMessage: auth.clearGlobalMessage,isLoggedIn: isLoggedIn,+ isLoggingOut: isLoggingOut,}), [auth.isInitialized,auth.username,@@ -85,6 +103,7 @@ export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ childrenlogout,initializeAuth,isLoggedIn,+ isLoggingOut,]);return (diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Logout.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Logout.tsxindex 4f0230b15..7ac63f79d 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Logout.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Logout.tsx@@ -15,8 +15,8 @@ const Logout: React.FC = () => {* Perform logout via async method to ensure logout is completed before navigating to home page.*/const performLogout = async () : Promise<void> => {+ // Logout via app context, this will automatically trigger a navigation to the login page.await app.logout();- // Let the auth context handle the navigation to the login page.};performLogout();diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsxindex 19b98dec2..ce108396e 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx@@ -52,7 +52,6 @@ const Unlock: React.FC = () => {const statusError = webApi.validateStatusResponse(statusResponse);if (statusError !== null) {await app.logout(t('common.errors.' + statusError));- navigate('/logout');}setIsInitialLoading(false);};@@ -126,7 +125,6 @@ const Unlock: React.FC = () => {// Check if it's a version incompatibility errorif (err instanceof VaultVersionIncompatibleError) {await app.logout(err.message);- navigate('/logout');} else {setError(t('auth.errors.wrongPassword'));}