浏览代码

feat: getAccountsURL()

httpjamesm 1 年之前
父节点
当前提交
ad1fab8edb

+ 2 - 1
apps/photos/src/components/Sidebar/UtilitySection.tsx

@@ -13,6 +13,7 @@ import { AppContext } from 'pages/_app';
 // import mlIDbStorage from 'utils/storage/mlIDbStorage';
 // import mlIDbStorage from 'utils/storage/mlIDbStorage';
 import { APPS, CLIENT_PACKAGE_NAMES } from '@ente/shared/apps/constants';
 import { APPS, CLIENT_PACKAGE_NAMES } from '@ente/shared/apps/constants';
 import ThemeSwitcher from '@ente/shared/components/ThemeSwitcher';
 import ThemeSwitcher from '@ente/shared/components/ThemeSwitcher';
+import { getAccountsURL } from '@ente/shared/network/api';
 import { LS_KEYS, getData } from '@ente/shared/storage/localStorage';
 import { LS_KEYS, getData } from '@ente/shared/storage/localStorage';
 import { THEME_COLOR } from '@ente/shared/themes/constants';
 import { THEME_COLOR } from '@ente/shared/themes/constants';
 import { EnteMenuItem } from 'components/Menu/EnteMenuItem';
 import { EnteMenuItem } from 'components/Menu/EnteMenuItem';
@@ -74,7 +75,7 @@ export default function UtilitySection({ closeSidebar }) {
         const serialized = JSON.stringify(userData);
         const serialized = JSON.stringify(userData);
         const serializedB64 = window.btoa(serialized);
         const serializedB64 = window.btoa(serialized);
 
 
-        window.location.href = `${process.env.NEXT_PUBLIC_ACCOUNTS_ENDPOINT}${ACCOUNTS_PAGES.ACCOUNT_HANDOFF
+        window.location.href = `${getAccountsURL()}${ACCOUNTS_PAGES.ACCOUNT_HANDOFF
             }?package=${CLIENT_PACKAGE_NAMES.get(APPS.PHOTOS)}#${serializedB64}`;
             }?package=${CLIENT_PACKAGE_NAMES.get(APPS.PHOTOS)}#${serializedB64}`;
     };
     };
 
 

+ 28 - 27
packages/accounts/pages/credentials.tsx

@@ -2,57 +2,57 @@ import { useEffect, useState } from 'react';
 
 
 import { t } from 'i18next';
 import { t } from 'i18next';
 
 
+import {
+    decryptAndStoreToken,
+    generateAndSaveIntermediateKeyAttributes,
+    generateLoginSubKey,
+    saveKeyInSessionStore,
+} from '@ente/shared/crypto/helpers';
 import {
 import {
     clearData,
     clearData,
     getData,
     getData,
     LS_KEYS,
     LS_KEYS,
     setData,
     setData,
 } from '@ente/shared/storage/localStorage';
 } from '@ente/shared/storage/localStorage';
-import { PAGES } from '../constants/pages';
 import {
 import {
-    SESSION_KEYS,
     getKey,
     getKey,
     removeKey,
     removeKey,
+    SESSION_KEYS,
     setKey,
     setKey,
 } from '@ente/shared/storage/sessionStorage';
 } from '@ente/shared/storage/sessionStorage';
-import {
-    decryptAndStoreToken,
-    generateAndSaveIntermediateKeyAttributes,
-    generateLoginSubKey,
-    saveKeyInSessionStore,
-} from '@ente/shared/crypto/helpers';
+import { PAGES } from '../constants/pages';
 import { generateSRPSetupAttributes } from '../services/srp';
 import { generateSRPSetupAttributes } from '../services/srp';
 import { logoutUser } from '../services/user';
 import { logoutUser } from '../services/user';
 
 
-import { configureSRP, loginViaSRP } from '../services/srp';
-import { getSRPAttributes } from '../api/srp';
-import { SRPAttributes } from '../types/srp';
-
-import {
-    isFirstLogin,
-    setIsFirstLogin,
-} from '@ente/shared/storage/localStorage/helpers';
-import { KeyAttributes, User } from '@ente/shared/user/types';
+import { VerticallyCentered } from '@ente/shared/components/Container';
+import EnteSpinner from '@ente/shared/components/EnteSpinner';
 import FormPaper from '@ente/shared/components/Form/FormPaper';
 import FormPaper from '@ente/shared/components/Form/FormPaper';
-import FormPaperTitle from '@ente/shared/components/Form/FormPaper/Title';
 import FormPaperFooter from '@ente/shared/components/Form/FormPaper/Footer';
 import FormPaperFooter from '@ente/shared/components/Form/FormPaper/Footer';
+import FormPaperTitle from '@ente/shared/components/Form/FormPaper/Title';
 import LinkButton from '@ente/shared/components/LinkButton';
 import LinkButton from '@ente/shared/components/LinkButton';
-import isElectron from 'is-electron';
-import { VerticallyCentered } from '@ente/shared/components/Container';
-import EnteSpinner from '@ente/shared/components/EnteSpinner';
 import VerifyMasterPasswordForm, {
 import VerifyMasterPasswordForm, {
     VerifyMasterPasswordFormProps,
     VerifyMasterPasswordFormProps,
 } from '@ente/shared/components/VerifyMasterPasswordForm';
 } from '@ente/shared/components/VerifyMasterPasswordForm';
+import { getAccountsURL } from '@ente/shared/network/api';
+import {
+    isFirstLogin,
+    setIsFirstLogin,
+} from '@ente/shared/storage/localStorage/helpers';
+import { KeyAttributes, User } from '@ente/shared/user/types';
+import isElectron from 'is-electron';
+import { getSRPAttributes } from '../api/srp';
+import { configureSRP, loginViaSRP } from '../services/srp';
+import { SRPAttributes } from '../types/srp';
 // import { APPS, getAppName } from '@ente/shared/apps';
 // import { APPS, getAppName } from '@ente/shared/apps';
-import { addLocalLog } from '@ente/shared/logging';
+import { APP_HOMES } from '@ente/shared/apps/constants';
+import { PageProps } from '@ente/shared/apps/types';
 import ComlinkCryptoWorker from '@ente/shared/crypto';
 import ComlinkCryptoWorker from '@ente/shared/crypto';
 import { B64EncryptionResult } from '@ente/shared/crypto/types';
 import { B64EncryptionResult } from '@ente/shared/crypto/types';
+import ElectronAPIs from '@ente/shared/electron';
 import { CustomError } from '@ente/shared/error';
 import { CustomError } from '@ente/shared/error';
-import InMemoryStore, { MS_KEYS } from '@ente/shared/storage/InMemoryStore';
-import { PageProps } from '@ente/shared/apps/types';
-import { APP_HOMES } from '@ente/shared/apps/constants';
+import { addLocalLog } from '@ente/shared/logging';
 import { logError } from '@ente/shared/sentry';
 import { logError } from '@ente/shared/sentry';
-import ElectronAPIs from '@ente/shared/electron';
+import InMemoryStore, { MS_KEYS } from '@ente/shared/storage/InMemoryStore';
 
 
 export default function Credentials({
 export default function Credentials({
     appContext,
     appContext,
@@ -166,7 +166,8 @@ export default function Credentials({
                         isTwoFactorPasskeysEnabled: true,
                         isTwoFactorPasskeysEnabled: true,
                     });
                     });
                     InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.ROOT);
                     InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.ROOT);
-                    window.location.href = `${process.env.NEXT_PUBLIC_ACCOUNTS_ENDPOINT}/passkeys/flow?passkeySessionID=${passkeySessionID}&redirect=${window.location.origin}/passkeys/finish`;
+                    window.location.href = `${getAccountsURL()}/passkeys/flow?passkeySessionID=${passkeySessionID}&redirect=${window.location.origin
+                        }/passkeys/finish`;
                     return;
                     return;
                 } else if (twoFactorSessionID) {
                 } else if (twoFactorSessionID) {
                     const sessionKeyAttributes =
                     const sessionKeyAttributes =

+ 3 - 1
packages/accounts/pages/verify.tsx

@@ -14,6 +14,7 @@ import SingleInputForm, {
     SingleInputFormProps,
     SingleInputFormProps,
 } from '@ente/shared/components/SingleInputForm';
 } from '@ente/shared/components/SingleInputForm';
 import { ApiError } from '@ente/shared/error';
 import { ApiError } from '@ente/shared/error';
+import { getAccountsURL } from '@ente/shared/network/api';
 import InMemoryStore, { MS_KEYS } from '@ente/shared/storage/InMemoryStore';
 import InMemoryStore, { MS_KEYS } from '@ente/shared/storage/InMemoryStore';
 import { clearFiles } from '@ente/shared/storage/localForage/helpers';
 import { clearFiles } from '@ente/shared/storage/localForage/helpers';
 import { LS_KEYS, getData, setData } from '@ente/shared/storage/localStorage';
 import { LS_KEYS, getData, setData } from '@ente/shared/storage/localStorage';
@@ -80,7 +81,8 @@ export default function VerifyPage({ appContext, router, appName }: PageProps) {
                     isTwoFactorPasskeysEnabled: true,
                     isTwoFactorPasskeysEnabled: true,
                 });
                 });
                 setIsFirstLogin(true);
                 setIsFirstLogin(true);
-                window.location.href = `${process.env.NEXT_PUBLIC_ACCOUNTS_ENDPOINT}/passkeys/flow?passkeySessionID=${passkeySessionID}&redirect=${window.location.origin}/passkeys/finish`;
+                window.location.href = `${getAccountsURL()}/passkeys/flow?passkeySessionID=${passkeySessionID}&redirect=${window.location.origin
+                    }/passkeys/finish`;
                 router.push(PAGES.CREDENTIALS);
                 router.push(PAGES.CREDENTIALS);
             } else if (twoFactorSessionID) {
             } else if (twoFactorSessionID) {
                 setData(LS_KEYS.USER, {
                 setData(LS_KEYS.USER, {

+ 10 - 2
packages/shared/network/api.ts

@@ -88,6 +88,14 @@ export const getAuthURL = () => {
     return `https://auth.ente.io`;
     return `https://auth.ente.io`;
 };
 };
 
 
+export const getAccountsURL = () => {
+    const accountsURL = process.env.NEXT_PUBLIC_ENTE_ACCOUNTS_ENDPOINT;
+    if (isDevDeployment() && accountsURL) {
+        return accountsURL;
+    }
+    return `https://accounts.ente.io`;
+};
+
 export const getSentryTunnelURL = () => {
 export const getSentryTunnelURL = () => {
     return `https://sentry-reporter.ente.io`;
     return `https://sentry-reporter.ente.io`;
 };
 };
@@ -103,9 +111,9 @@ export const isDevDeployment = () => {
     if (globalThis?.location) {
     if (globalThis?.location) {
         return (
         return (
             process.env.NEXT_PUBLIC_ENTE_WEB_ENDPOINT ===
             process.env.NEXT_PUBLIC_ENTE_WEB_ENDPOINT ===
-                globalThis.location.origin ||
+            globalThis.location.origin ||
             process.env.NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT ===
             process.env.NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT ===
-                globalThis.location.origin ||
+            globalThis.location.origin ||
             process.env.NEXT_PUBLIC_IS_TEST_APP === 'true' ||
             process.env.NEXT_PUBLIC_IS_TEST_APP === 'true' ||
             process.env.NODE_ENV === 'development'
             process.env.NODE_ENV === 'development'
         );
         );