Skip to content

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

Show target API endpoint on login form (#541)

Leendert de Borst38ee886be2b9
diff --git a/browser-extensions/chrome/src/app/components/Layout/Header.tsx b/browser-extensions/chrome/src/app/components/Layout/Header.tsx
index 2726b5908..49dae7ef7 100644
--- a/browser-extensions/chrome/src/app/components/Layout/Header.tsx
+++ b/browser-extensions/chrome/src/app/components/Layout/Header.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import { UserMenu } from './UserMenu';
import { useNavigate, useLocation } from 'react-router-dom';
import { useAuth } from '../../context/AuthContext';
-
+import { AppInfo } from '../../../shared/AppInfo';
/**
* Header props.
*/
@@ -29,7 +29,12 @@ const Header: React.FC<HeaderProps> = ({
*/
const openClientTab = async () : Promise<void> => {
const setting = await chrome.storage.local.get(['clientUrl']);
- window.open(setting.clientUrl, '_blank');
+ let clientUrl = AppInfo.DEFAULT_CLIENT_URL;
+ if (setting.clientUrl.length > 0) {
+ clientUrl = setting.clientUrl;
+ }
+
+ window.open(clientUrl, '_blank');
};
// Updated route matching logic to handle URL parameters
diff --git a/browser-extensions/chrome/src/app/components/LoginServerInfo.tsx b/browser-extensions/chrome/src/app/components/LoginServerInfo.tsx
new file mode 100644
index 000000000..33209c974
--- /dev/null
+++ b/browser-extensions/chrome/src/app/components/LoginServerInfo.tsx
@@ -0,0 +1,48 @@
+import React, { useState, useEffect } from 'react';
+import { useNavigate } from 'react-router-dom';
+
+/**
+ * Component for displaying the login server information.
+ */
+const LoginServerInfo: React.FC = () => {
+ const [baseUrl, setBaseUrl] = useState<string>('');
+ const navigate = useNavigate();
+
+ useEffect(() => {
+ /**
+ * Loads the base URL for the login server.
+ */
+ const loadApiUrl = async () : Promise<void> => {
+ // TODO: store base webapi configurable in one place.
+ const result = await chrome.storage.local.get(['apiUrl']);
+ setBaseUrl(result.apiUrl || 'https://api.aliasvault.net/');
+ };
+ loadApiUrl();
+ }, []);
+
+ const isDefaultServer = !baseUrl || baseUrl === 'https://api.aliasvault.net/';
+ const displayUrl = isDefaultServer ? 'aliasvault.net' : new URL(baseUrl).hostname;
+
+ /**
+ * Handles the click event for the login server information.
+ */
+ const handleClick = () : void => {
+ navigate('/auth-settings');
+ };
+
+ return (
+ <div className="text-xs text-gray-600 dark:text-gray-400 mb-4">
+ (Logging into{' '}
+ <button
+ onClick={handleClick}
+ type="button"
+ className="text-orange-500 hover:text-orange-600 dark:text-orange-400 dark:hover:text-orange-500 underline"
+ >
+ {displayUrl}
+ </button>
+ )
+ </div>
+ );
+};
+
+export default LoginServerInfo;
\ No newline at end of file
diff --git a/browser-extensions/chrome/src/app/pages/AuthSettings.tsx b/browser-extensions/chrome/src/app/pages/AuthSettings.tsx
index 1a1aa7f62..d97e32fed 100644
--- a/browser-extensions/chrome/src/app/pages/AuthSettings.tsx
+++ b/browser-extensions/chrome/src/app/pages/AuthSettings.tsx
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from 'react';
+import { AppInfo } from '../../shared/AppInfo';
type ApiOption = {
label: string;
@@ -6,7 +7,7 @@ type ApiOption = {
};
const DEFAULT_OPTIONS: ApiOption[] = [
- { label: 'Aliasvault.net', value: 'https://app.aliasvault.net/api' },
+ { label: 'Aliasvault.net', value: AppInfo.DEFAULT_API_URL },
{ label: 'Self-hosted', value: 'custom' }
];
diff --git a/browser-extensions/chrome/src/app/pages/Login.tsx b/browser-extensions/chrome/src/app/pages/Login.tsx
index c4f46f42f..c8b6eb340 100644
--- a/browser-extensions/chrome/src/app/pages/Login.tsx
+++ b/browser-extensions/chrome/src/app/pages/Login.tsx
@@ -9,6 +9,7 @@ import SrpUtility from '../utils/SrpUtility';
import { useLoading } from '../context/LoadingContext';
import { VaultResponse } from '../../shared/types/webapi/VaultResponse';
import { LoginResponse } from '../../shared/types/webapi/Login';
+import LoginServerInfo from '../components/LoginServerInfo';
/**
* Login page
@@ -266,7 +267,8 @@ const Login: React.FC = () => {
{error}
</div>
)}
- <h2 className="text-xl font-bold mb-4 dark:text-gray-200">Login to AliasVault</h2>
+ <h2 className="text-xl font-bold dark:text-gray-200">Login to AliasVault</h2>
+ <LoginServerInfo />
<div className="mb-4">
<label className="block text-gray-700 dark:text-gray-200 text-sm font-bold mb-2" htmlFor="username">
Username or email
diff --git a/browser-extensions/chrome/src/shared/AppInfo.ts b/browser-extensions/chrome/src/shared/AppInfo.ts
index c79576321..e5a6d6d94 100644
--- a/browser-extensions/chrome/src/shared/AppInfo.ts
+++ b/browser-extensions/chrome/src/shared/AppInfo.ts
@@ -1,5 +1,6 @@
/**
- * AppInfo class which contains information about the application version.
+ * AppInfo class which contains information about the application version
+ * and default server URLs.
*/
export class AppInfo {
/**
@@ -24,6 +25,16 @@ export class AppInfo {
*/
public static readonly CLIENT_NAME = 'chrome';
+ /**
+ * The default AliasVault client URL.
+ */
+ public static readonly DEFAULT_CLIENT_URL = 'https://app.aliasvault.net';
+
+ /**
+ * The default AliasVault web API URL.
+ */
+ public static readonly DEFAULT_API_URL = 'https://app.aliasvault.net/api';
+
/**
* Prevent instantiation of this utility class
*/
diff --git a/browser-extensions/chrome/src/shared/WebApiService.ts b/browser-extensions/chrome/src/shared/WebApiService.ts
index 93c08bd5e..bdd1df775 100644
--- a/browser-extensions/chrome/src/shared/WebApiService.ts
+++ b/browser-extensions/chrome/src/shared/WebApiService.ts
@@ -32,7 +32,7 @@ export class WebApiService {
*/
private async getBaseUrl(): Promise<string> {
const result = await chrome.storage.local.get(['apiUrl']);
- return (result.apiUrl ?? 'https://app.aliasvault.net/api').replace(/\/$/, '') + '/v1/';
+ return (result.apiUrl ?? AppInfo.DEFAULT_API_URL).replace(/\/$/, '') + '/v1/';
}
/**