mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-03-29 03:53:39 -04:00
Add known vault version check: logout if vault is newer than the app knows about (#957)
This commit is contained in:
committed by
Leendert de Borst
parent
f3ad61a77a
commit
62732a71f0
@@ -188,6 +188,7 @@ export default function LoginScreen() : React.ReactNode {
|
||||
// Show modal with error message
|
||||
Alert.alert('Error', message);
|
||||
webApi.logout(message);
|
||||
setIsLoading(false);
|
||||
},
|
||||
/**
|
||||
* On upgrade required.
|
||||
|
||||
@@ -99,7 +99,8 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
|
||||
}, [sqliteClient, unlockVault]);
|
||||
|
||||
/**
|
||||
* Check if there are any pending migrations.
|
||||
* Check if there are any pending migrations. This method also checks if the current vault version is known to the client.
|
||||
* If the current vault version is not known to the client, the method will throw an exception which causes the app to logout.
|
||||
*/
|
||||
const hasPendingMigrations = useCallback(async () => {
|
||||
const currentVersion = await sqliteClient.getDatabaseVersion();
|
||||
|
||||
@@ -114,7 +114,7 @@ export const useVaultSync = () : {
|
||||
try {
|
||||
await dbContext.initializeDatabase(vaultResponseJson as VaultResponse);
|
||||
|
||||
// Check if the vault is up to date, if not, redirect to the upgrade page.
|
||||
// Check if the current vault version is known and up to date, if not known trigger an exception, if not up to date redirect to the upgrade page.
|
||||
if (await dbContext.hasPendingMigrations()) {
|
||||
onUpgradeRequired?.();
|
||||
return false;
|
||||
|
||||
@@ -16,11 +16,6 @@ export class AppInfo {
|
||||
*/
|
||||
public static readonly MIN_SERVER_VERSION = '0.12.0-dev';
|
||||
|
||||
/**
|
||||
* The minimum supported AliasVault client vault version.
|
||||
*/
|
||||
public static readonly MIN_VAULT_VERSION = '1.4.1';
|
||||
|
||||
/**
|
||||
* The client name to use in the X-AliasVault-Client header.
|
||||
* Detects the specific browser being used.
|
||||
@@ -54,15 +49,6 @@ export class AppInfo {
|
||||
*/
|
||||
private constructor() {}
|
||||
|
||||
/**
|
||||
* Checks if a given vault version is supported
|
||||
* @param vaultVersion The version to check
|
||||
* @returns boolean indicating if the version is supported
|
||||
*/
|
||||
public static isVaultVersionSupported(vaultVersion: string): boolean {
|
||||
return this.versionGreaterThanOrEqualTo(vaultVersion, this.MIN_VAULT_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given server version is supported
|
||||
* @param serverVersion The version to check
|
||||
|
||||
@@ -558,8 +558,8 @@ class SqliteClient {
|
||||
|
||||
/**
|
||||
* Get the current database version from the migrations history.
|
||||
* Returns the semantic version (e.g., "1.4.1") from the latest migration.
|
||||
* Returns null if no migrations are found.
|
||||
* Returns the internal version information that matches the current database version.
|
||||
* Returns null if no matching version is found.
|
||||
*/
|
||||
public async getDatabaseVersion(): Promise<VaultVersion> {
|
||||
try {
|
||||
@@ -591,7 +591,7 @@ class SqliteClient {
|
||||
const currentVersionRevision = allVersions.find(v => v.version === currentVersion);
|
||||
|
||||
if (!currentVersionRevision) {
|
||||
throw new Error(`Current version ${currentVersion} not found in available vault versions.`);
|
||||
throw new Error(`This app is outdated and cannot be used to access this vault. Please update this app to continue.`);
|
||||
}
|
||||
|
||||
return currentVersionRevision;
|
||||
|
||||
@@ -308,29 +308,6 @@ export class WebApiService {
|
||||
return 'Your account does not have a vault yet. Please complete the tutorial in the AliasVault web client before using the browser extension.';
|
||||
}
|
||||
|
||||
if (!AppInfo.isVaultVersionSupported(vaultResponseJson.vault.version)) {
|
||||
return 'Your vault is outdated. Please login via the web client to update your vault.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the status response and returns an error message if validation fails.
|
||||
*/
|
||||
public validateStatusResponse(statusResponse: StatusResponse): string | null {
|
||||
if (statusResponse.serverVersion === '0.0.0') {
|
||||
return 'The AliasVault server is not available. Please try again later or contact support if the problem persists.';
|
||||
}
|
||||
|
||||
if (!statusResponse.clientVersionSupported) {
|
||||
return 'This version of the AliasVault mobile app is not supported by the server anymore. Please update your app to the latest version.';
|
||||
}
|
||||
|
||||
if (!AppInfo.isServerVersionSupported(statusResponse.serverVersion)) {
|
||||
return 'The AliasVault server needs to be updated to a newer version in order to use this mobile app. Please contact support if you need help.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ export type VaultVersion = {
|
||||
revision: number;
|
||||
|
||||
/**
|
||||
* The version number (e.g., "1.5.0")
|
||||
* The internal migration version number that equals the AliasClientDb database version (e.g., "1.5.0").
|
||||
* This is not the same as the AliasVault server release version.
|
||||
*/
|
||||
version: string;
|
||||
|
||||
@@ -20,7 +21,7 @@ export type VaultVersion = {
|
||||
/**
|
||||
* The AliasVault release that this vault version was introduced in (e.g., "0.14.0").
|
||||
* This value is shown to the user in the UI instead of the actual vault version in order to
|
||||
* avoid potential confusion. The "version" field is the actual vault database version. While
|
||||
* avoid potential confusion. The "version" field is the actual AliasClientDb database version. While
|
||||
* this field is just for display purposes.
|
||||
*/
|
||||
releaseVersion: string;
|
||||
|
||||
Reference in New Issue
Block a user