mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-09 07:46:13 -04:00
Detect vault locked error and redirect to vault unlock instead of showing error
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { MaterialIcons } from '@expo/vector-icons';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { router, useLocalSearchParams } from 'expo-router';
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { StyleSheet, View, ScrollView, Dimensions, Text, Platform } from 'react-native';
|
||||
|
||||
import { copyToClipboard } from '@/utils/ClipboardUtility';
|
||||
import { isVaultLockedError } from '@/utils/types/errors/AppErrorCodes';
|
||||
|
||||
import { useColors } from '@/hooks/useColorScheme';
|
||||
import { useLogout } from '@/hooks/useLogout';
|
||||
@@ -31,6 +32,18 @@ export default function VaultErrorScreen() : React.ReactNode {
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
/*
|
||||
* Central safety net: if the error indicates the in-memory vault was cleared
|
||||
* (auto-lock timeout), redirect to the reinitialize flow instead of showing
|
||||
* the fatal-error screen.
|
||||
*/
|
||||
const shouldReinitialize = isVaultLockedError(errorMessage) && errorSource !== 'reinitialize';
|
||||
useEffect(() => {
|
||||
if (shouldReinitialize) {
|
||||
router.replace('/reinitialize');
|
||||
}
|
||||
}, [shouldReinitialize]);
|
||||
|
||||
/**
|
||||
* Copy the full error details to clipboard for sharing with support.
|
||||
*/
|
||||
@@ -56,6 +69,10 @@ export default function VaultErrorScreen() : React.ReactNode {
|
||||
router.replace('/initialize');
|
||||
}, []);
|
||||
|
||||
if (shouldReinitialize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
appName: {
|
||||
color: colors.text,
|
||||
|
||||
@@ -135,6 +135,20 @@ export function getAppErrorCode(error: unknown): AppErrorCode | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect a "vault locked" error — i.e. the in-memory database has been cleared
|
||||
* (auto-lock timeout, vault evicted from memory).
|
||||
*/
|
||||
export function isVaultLockedError(error: unknown): boolean {
|
||||
const message =
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: typeof error === 'string'
|
||||
? error
|
||||
: '';
|
||||
return message.includes('Database not initialized');
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract error code from a string (e.g., "Error occurred (Code: E-501)" -> "E-501")
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user