Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add generic vault validate method (#541)

Leendert de Borst620aeaf941df
diff --git a/browser-extensions/chrome/src/app/pages/Login.tsx b/browser-extensions/chrome/src/app/pages/Login.tsx
index ea61c4942..53d03db41 100644
--- a/browser-extensions/chrome/src/app/pages/Login.tsx
+++ b/browser-extensions/chrome/src/app/pages/Login.tsx
@@ -44,6 +44,29 @@ const Login: React.FC = () => {
loadClientUrl();
}, []);
+ /**
+ * Validates the vault response and returns an error message if validation fails
+ */
+ const validateVaultResponse = (vaultResponseJson: VaultResponse): string | null => {
+ /**
+ * Status 0 = OK, vault is ready.
+ * Status 1 = Merge required, which only the web client supports.
+ */
+ if (vaultResponseJson.status !== 0) {
+ return 'Your vault needs to be updated. Please login on the AliasVault website and follow the steps.';
+ }
+
+ if (!vaultResponseJson.vault?.blob) {
+ 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;
+ };
+
/**
* Handle submit
*/
@@ -103,16 +126,9 @@ const Login: React.FC = () => {
'Authorization': `Bearer ${validationResponse.token.token}`
} });
- // Return error if vault blob does not exist yet.
- if (!vaultResponseJson.vault?.blob) {
- setError('Your account does not have a vault yet. Please complete the tutorial in the AliasVault web client before using the browser extension.');
- hideLoading();
- return;
- }
-
- // Check if vault version is supported.
- if (!AppInfo.isVaultVersionSupported(vaultResponseJson.vault.version)) {
- setError('Your vault is outdated. Please login via the web client to update your vault.');
+ const vaultError = validateVaultResponse(vaultResponseJson);
+ if (vaultError) {
+ setError(vaultError);
hideLoading();
return;
}
@@ -165,19 +181,13 @@ const Login: React.FC = () => {
'Authorization': `Bearer ${validationResponse.token.token}`
} });
- // Check if vault blob exists
- if (!vaultResponseJson.vault?.blob) {
- setError('Your account does not have a vault yet. Please complete the tutorial in the AliasVault web client before using the browser extension.');
+ const vaultError = validateVaultResponse(vaultResponseJson);
+ if (vaultError) {
+ setError(vaultError);
hideLoading();
return;
}
- // Check if vault version is supported.
- if (!AppInfo.isVaultVersionSupported(vaultResponseJson.vault.version)) {
- setError('Your vault is outdated. Please login via the web client to update your vault.');
- hideLoading();
- return;
- }
// All is good. Store auth info which makes the user logged in.
await authContext.login(credentials.username, validationResponse.token.token, validationResponse.token.refreshToken);