@digitaldefiance/express-suite-react-components 5.0.2 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -4
- package/src/auth/AdminRoute.d.ts +8 -0
- package/src/auth/AdminRoute.d.ts.map +1 -0
- package/src/auth/AdminRoute.js +28 -0
- package/src/auth/Private.d.ts +6 -0
- package/src/auth/Private.d.ts.map +1 -0
- package/src/auth/Private.js +14 -0
- package/src/auth/PrivateRoute.d.ts +8 -0
- package/src/auth/PrivateRoute.d.ts.map +1 -0
- package/src/auth/PrivateRoute.js +23 -0
- package/src/auth/UnAuth.d.ts +6 -0
- package/src/auth/UnAuth.d.ts.map +1 -0
- package/src/auth/UnAuth.js +14 -0
- package/src/auth/UnAuthRoute.d.ts +8 -0
- package/src/auth/UnAuthRoute.d.ts.map +1 -0
- package/src/auth/UnAuthRoute.js +22 -0
- package/src/auth/{index.ts → index.d.ts} +3 -2
- package/src/auth/index.d.ts.map +1 -0
- package/src/auth/index.js +12 -0
- package/src/components/ApiAccess.d.ts +16 -0
- package/src/components/ApiAccess.d.ts.map +1 -0
- package/src/components/ApiAccess.js +77 -0
- package/src/components/BackupCodeLoginForm.d.ts +43 -0
- package/src/components/BackupCodeLoginForm.d.ts.map +1 -0
- package/src/components/BackupCodeLoginForm.js +139 -0
- package/src/components/BackupCodesForm.d.ts +26 -0
- package/src/components/BackupCodesForm.d.ts.map +1 -0
- package/src/components/BackupCodesForm.js +120 -0
- package/src/components/CategoryMenu.d.ts +17 -0
- package/src/components/CategoryMenu.d.ts.map +1 -0
- package/src/components/CategoryMenu.js +65 -0
- package/src/components/ChangePasswordForm.d.ts +26 -0
- package/src/components/ChangePasswordForm.d.ts.map +1 -0
- package/src/components/ChangePasswordForm.js +78 -0
- package/src/components/ConfirmationDialog.d.ts +13 -0
- package/src/components/ConfirmationDialog.d.ts.map +1 -0
- package/src/components/ConfirmationDialog.js +10 -0
- package/src/components/CurrencyCodeSelector.d.ts +9 -0
- package/src/components/CurrencyCodeSelector.d.ts.map +1 -0
- package/src/components/CurrencyCodeSelector.js +31 -0
- package/src/components/CurrencyInput.d.ts +13 -0
- package/src/components/CurrencyInput.d.ts.map +1 -0
- package/src/components/CurrencyInput.js +22 -0
- package/src/components/DashboardPage.d.ts +8 -0
- package/src/components/DashboardPage.d.ts.map +1 -0
- package/src/components/DashboardPage.js +10 -0
- package/src/components/DropdownMenu.d.ts +13 -0
- package/src/components/DropdownMenu.d.ts.map +1 -0
- package/src/components/DropdownMenu.js +63 -0
- package/src/components/ExpirationSecondsSelector.d.ts +13 -0
- package/src/components/ExpirationSecondsSelector.d.ts.map +1 -0
- package/src/components/ExpirationSecondsSelector.js +32 -0
- package/src/components/FakeEmailAdminPanel.d.ts +23 -0
- package/src/components/FakeEmailAdminPanel.d.ts.map +1 -0
- package/src/components/FakeEmailAdminPanel.js +147 -0
- package/src/components/Flag.d.ts +20 -0
- package/src/components/Flag.d.ts.map +1 -0
- package/src/components/Flag.js +43 -0
- package/src/components/ForgotPasswordForm.d.ts +18 -0
- package/src/components/ForgotPasswordForm.d.ts.map +1 -0
- package/src/components/ForgotPasswordForm.js +61 -0
- package/src/components/LoginForm.d.ts +44 -0
- package/src/components/LoginForm.d.ts.map +1 -0
- package/src/components/LoginForm.js +123 -0
- package/src/components/LogoutPage.d.ts +8 -0
- package/src/components/LogoutPage.d.ts.map +1 -0
- package/src/components/LogoutPage.js +16 -0
- package/src/components/RegisterForm.d.ts +100 -0
- package/src/components/RegisterForm.d.ts.map +1 -0
- package/src/components/RegisterForm.js +306 -0
- package/src/components/ResetPasswordForm.d.ts +23 -0
- package/src/components/ResetPasswordForm.d.ts.map +1 -0
- package/src/components/ResetPasswordForm.js +78 -0
- package/src/components/SideMenu.d.ts +8 -0
- package/src/components/SideMenu.d.ts.map +1 -0
- package/src/components/SideMenu.js +25 -0
- package/src/components/SideMenuListItem.d.ts +13 -0
- package/src/components/SideMenuListItem.d.ts.map +1 -0
- package/src/components/SideMenuListItem.js +44 -0
- package/src/components/T.d.ts +7 -0
- package/src/components/T.d.ts.map +1 -0
- package/src/components/T.js +13 -0
- package/src/components/TDiv.d.ts +9 -0
- package/src/components/TDiv.d.ts.map +1 -0
- package/src/components/TDiv.js +14 -0
- package/src/components/TImgAlt.d.ts +10 -0
- package/src/components/TImgAlt.d.ts.map +1 -0
- package/src/components/TImgAlt.js +14 -0
- package/src/components/TopMenu.d.ts +50 -0
- package/src/components/TopMenu.d.ts.map +1 -0
- package/src/components/TopMenu.js +79 -0
- package/src/components/TotpSetupForm.d.ts +24 -0
- package/src/components/TotpSetupForm.d.ts.map +1 -0
- package/src/components/TotpSetupForm.js +82 -0
- package/src/components/TotpVerificationForm.d.ts +23 -0
- package/src/components/TotpVerificationForm.d.ts.map +1 -0
- package/src/components/TotpVerificationForm.js +66 -0
- package/src/components/TranslatedTitle.d.ts +8 -0
- package/src/components/TranslatedTitle.d.ts.map +1 -0
- package/src/components/TranslatedTitle.js +15 -0
- package/src/components/UserLanguageSelector.d.ts +4 -0
- package/src/components/UserLanguageSelector.d.ts.map +1 -0
- package/src/components/UserLanguageSelector.js +31 -0
- package/src/components/UserMenu.d.ts +4 -0
- package/src/components/UserMenu.d.ts.map +1 -0
- package/src/components/UserMenu.js +12 -0
- package/src/components/UserSettingsForm.d.ts +113 -0
- package/src/components/UserSettingsForm.d.ts.map +1 -0
- package/src/components/UserSettingsForm.js +269 -0
- package/src/components/VerifyEmailPage.d.ts +24 -0
- package/src/components/VerifyEmailPage.d.ts.map +1 -0
- package/src/components/VerifyEmailPage.js +81 -0
- package/src/components/{index.ts → index.d.ts} +1 -1
- package/src/components/index.d.ts.map +1 -0
- package/src/components/index.js +35 -0
- package/src/contexts/AuthProvider.d.ts +19 -0
- package/src/contexts/AuthProvider.d.ts.map +1 -0
- package/src/contexts/AuthProvider.js +514 -0
- package/src/contexts/I18nProvider.d.ts +27 -0
- package/src/contexts/I18nProvider.d.ts.map +1 -0
- package/src/contexts/I18nProvider.js +60 -0
- package/src/contexts/MenuContext.d.ts +28 -0
- package/src/contexts/MenuContext.d.ts.map +1 -0
- package/src/contexts/MenuContext.js +307 -0
- package/src/contexts/SuiteConfigProvider.d.ts +44 -0
- package/src/contexts/SuiteConfigProvider.d.ts.map +1 -0
- package/src/contexts/SuiteConfigProvider.js +43 -0
- package/src/contexts/ThemeProvider.d.ts +15 -0
- package/src/contexts/ThemeProvider.d.ts.map +1 -0
- package/src/contexts/ThemeProvider.js +36 -0
- package/src/contexts/auth-context.d.ts +172 -0
- package/src/contexts/auth-context.d.ts.map +1 -0
- package/src/contexts/auth-context.js +13 -0
- package/src/contexts/{index.ts → index.d.ts} +1 -0
- package/src/contexts/index.d.ts.map +1 -0
- package/src/contexts/index.js +8 -0
- package/src/hooks/{index.ts → index.d.ts} +1 -0
- package/src/hooks/index.d.ts.map +1 -0
- package/src/hooks/index.js +9 -0
- package/src/hooks/useAuthenticatedApi.d.ts +34 -0
- package/src/hooks/useAuthenticatedApi.d.ts.map +1 -0
- package/src/hooks/useAuthenticatedApi.js +46 -0
- package/src/hooks/useBackupCodes.d.ts +15 -0
- package/src/hooks/useBackupCodes.d.ts.map +1 -0
- package/src/hooks/useBackupCodes.js +74 -0
- package/src/hooks/useEmailVerification.d.ts +10 -0
- package/src/hooks/useEmailVerification.d.ts.map +1 -0
- package/src/hooks/useEmailVerification.js +40 -0
- package/src/hooks/useExpiringValue.d.ts +14 -0
- package/src/hooks/useExpiringValue.d.ts.map +1 -0
- package/src/hooks/useExpiringValue.js +53 -0
- package/src/hooks/useLocalStorage.d.ts +2 -0
- package/src/hooks/useLocalStorage.d.ts.map +1 -0
- package/src/hooks/useLocalStorage.js +15 -0
- package/src/hooks/useUserSettings.d.ts +48 -0
- package/src/hooks/useUserSettings.d.ts.map +1 -0
- package/src/hooks/useUserSettings.js +171 -0
- package/src/{index.ts → index.d.ts} +1 -1
- package/src/index.d.ts.map +1 -0
- package/src/index.js +12 -0
- package/src/interfaces/IAppConfig.d.ts +8 -0
- package/src/interfaces/IAppConfig.d.ts.map +1 -0
- package/src/interfaces/IAppConfig.js +2 -0
- package/src/interfaces/ICategoryConfig.d.ts +41 -0
- package/src/interfaces/ICategoryConfig.d.ts.map +1 -0
- package/src/interfaces/ICategoryConfig.js +2 -0
- package/src/interfaces/IMenuConfig.d.ts +28 -0
- package/src/interfaces/IMenuConfig.d.ts.map +1 -0
- package/src/interfaces/IMenuConfig.js +2 -0
- package/src/interfaces/IMenuOption.d.ts +82 -0
- package/src/interfaces/IMenuOption.d.ts.map +1 -0
- package/src/interfaces/IMenuOption.js +2 -0
- package/src/interfaces/{index.ts → index.d.ts} +1 -0
- package/src/interfaces/index.d.ts.map +1 -0
- package/src/interfaces/index.js +7 -0
- package/src/services/__mocks__/authService.d.ts +21 -0
- package/src/services/__mocks__/authService.d.ts.map +1 -0
- package/src/services/__mocks__/authService.js +15 -0
- package/src/services/api.d.ts +3 -0
- package/src/services/api.d.ts.map +1 -0
- package/src/services/api.js +14 -0
- package/src/services/authService.d.ts +126 -0
- package/src/services/authService.d.ts.map +1 -0
- package/src/services/authService.js +471 -0
- package/src/services/authenticatedApi.d.ts +3 -0
- package/src/services/authenticatedApi.d.ts.map +1 -0
- package/src/services/authenticatedApi.js +18 -0
- package/src/services/index.d.ts +4 -0
- package/src/services/index.d.ts.map +1 -0
- package/src/services/index.js +6 -0
- package/src/types/MenuType.d.ts +11 -0
- package/src/types/MenuType.d.ts.map +1 -0
- package/src/types/MenuType.js +12 -0
- package/src/types/expirationSeconds.d.ts +3 -0
- package/src/types/expirationSeconds.d.ts.map +1 -0
- package/src/types/expirationSeconds.js +17 -0
- package/src/types/index.d.ts +2 -0
- package/src/types/index.d.ts.map +1 -0
- package/src/types/index.js +4 -0
- package/src/types/translation.d.ts +10 -0
- package/src/types/translation.d.ts.map +1 -0
- package/src/types/translation.js +9 -0
- package/src/wrappers/BackupCodeLoginWrapper.d.ts +8 -0
- package/src/wrappers/BackupCodeLoginWrapper.d.ts.map +1 -0
- package/src/wrappers/BackupCodeLoginWrapper.js +20 -0
- package/src/wrappers/BackupCodesWrapper.d.ts +7 -0
- package/src/wrappers/BackupCodesWrapper.d.ts.map +1 -0
- package/src/wrappers/BackupCodesWrapper.js +17 -0
- package/src/wrappers/ChangePasswordFormWrapper.d.ts +8 -0
- package/src/wrappers/ChangePasswordFormWrapper.d.ts.map +1 -0
- package/src/wrappers/ChangePasswordFormWrapper.js +21 -0
- package/src/wrappers/ForgotPasswordFormWrapper.d.ts +8 -0
- package/src/wrappers/ForgotPasswordFormWrapper.d.ts.map +1 -0
- package/src/wrappers/ForgotPasswordFormWrapper.js +29 -0
- package/src/wrappers/LoginFormWrapper.d.ts +21 -0
- package/src/wrappers/LoginFormWrapper.d.ts.map +1 -0
- package/src/wrappers/LoginFormWrapper.js +72 -0
- package/src/wrappers/LogoutPageWrapper.d.ts +9 -0
- package/src/wrappers/LogoutPageWrapper.d.ts.map +1 -0
- package/src/wrappers/LogoutPageWrapper.js +21 -0
- package/src/wrappers/RegisterFormWrapper.d.ts +20 -0
- package/src/wrappers/RegisterFormWrapper.d.ts.map +1 -0
- package/src/wrappers/RegisterFormWrapper.js +51 -0
- package/src/wrappers/ResetPasswordFormWrapper.d.ts +9 -0
- package/src/wrappers/ResetPasswordFormWrapper.d.ts.map +1 -0
- package/src/wrappers/ResetPasswordFormWrapper.js +34 -0
- package/src/wrappers/UserSettingsFormWrapper.d.ts +29 -0
- package/src/wrappers/UserSettingsFormWrapper.d.ts.map +1 -0
- package/src/wrappers/UserSettingsFormWrapper.js +95 -0
- package/src/wrappers/VerifyEmailPageWrapper.d.ts +8 -0
- package/src/wrappers/VerifyEmailPageWrapper.d.ts.map +1 -0
- package/src/wrappers/VerifyEmailPageWrapper.js +21 -0
- package/src/wrappers/{index.tsx → index.d.ts} +1 -10
- package/src/wrappers/index.d.ts.map +1 -0
- package/src/wrappers/index.js +24 -0
- package/LICENSE +0 -21
- package/src/auth/AdminRoute.tsx +0 -54
- package/src/auth/Private.tsx +0 -17
- package/src/auth/PrivateRoute.tsx +0 -28
- package/src/auth/UnAuth.tsx +0 -16
- package/src/auth/UnAuthRoute.tsx +0 -30
- package/src/components/ApiAccess.tsx +0 -175
- package/src/components/BackupCodeLoginForm.tsx +0 -489
- package/src/components/BackupCodesForm.tsx +0 -287
- package/src/components/CategoryMenu.tsx +0 -155
- package/src/components/ChangePasswordForm.tsx +0 -273
- package/src/components/ConfirmationDialog.tsx +0 -48
- package/src/components/CurrencyCodeSelector.tsx +0 -60
- package/src/components/CurrencyInput.tsx +0 -80
- package/src/components/DashboardPage.tsx +0 -24
- package/src/components/DropdownMenu.tsx +0 -105
- package/src/components/ExpirationSecondsSelector.tsx +0 -60
- package/src/components/FakeEmailAdminPanel.tsx +0 -374
- package/src/components/Flag.tsx +0 -52
- package/src/components/ForgotPasswordForm.tsx +0 -174
- package/src/components/LoginForm.tsx +0 -468
- package/src/components/LogoutPage.tsx +0 -21
- package/src/components/RegisterForm.tsx +0 -1169
- package/src/components/ResetPasswordForm.tsx +0 -247
- package/src/components/SideMenu.tsx +0 -46
- package/src/components/SideMenuListItem.tsx +0 -75
- package/src/components/T.tsx +0 -24
- package/src/components/TDiv.tsx +0 -26
- package/src/components/TImgAlt.tsx +0 -28
- package/src/components/TopMenu.tsx +0 -252
- package/src/components/TotpSetupForm.tsx +0 -188
- package/src/components/TotpVerificationForm.tsx +0 -148
- package/src/components/TranslatedTitle.tsx +0 -31
- package/src/components/UserLanguageSelector.tsx +0 -45
- package/src/components/UserMenu.tsx +0 -15
- package/src/components/UserSettingsForm.tsx +0 -904
- package/src/components/VerifyEmailPage.tsx +0 -222
- package/src/components/__tests__/RegisterForm.totp.spec.tsx +0 -377
- package/src/components/__tests__/TotpSetupForm.spec.tsx +0 -258
- package/src/components/__tests__/TotpVerificationForm.spec.tsx +0 -259
- package/src/components/__tests__/UserSettingsForm.totp.spec.tsx +0 -396
- package/src/contexts/AuthProvider.spec.tsx +0 -1284
- package/src/contexts/AuthProvider.tsx +0 -977
- package/src/contexts/I18nProvider.tsx +0 -164
- package/src/contexts/MenuContext.tsx +0 -426
- package/src/contexts/SuiteConfigProvider.tsx +0 -93
- package/src/contexts/ThemeProvider.tsx +0 -67
- package/src/hooks/useAuthenticatedApi.tsx +0 -67
- package/src/hooks/useBackupCodes.ts +0 -105
- package/src/hooks/useEmailVerification.ts +0 -54
- package/src/hooks/useExpiringValue.ts +0 -78
- package/src/hooks/useLocalStorage.ts +0 -18
- package/src/hooks/useUserSettings.ts +0 -271
- package/src/interfaces/IAppConfig.ts +0 -7
- package/src/interfaces/ICategoryConfig.ts +0 -41
- package/src/interfaces/IMenuConfig.ts +0 -28
- package/src/interfaces/IMenuOption.ts +0 -79
- package/src/services/__mocks__/authService.ts +0 -14
- package/src/services/__tests__/authService.totp.property.spec.ts +0 -360
- package/src/services/__tests__/authService.totp.spec.ts +0 -439
- package/src/services/api.ts +0 -13
- package/src/services/authService.ts +0 -692
- package/src/services/authenticatedApi.ts +0 -17
- package/src/services/index.ts +0 -3
- package/src/types/MenuType.ts +0 -15
- package/src/types/expirationSeconds.ts +0 -18
- package/src/types/index.ts +0 -1
- package/src/types/translation.ts +0 -20
- package/src/wrappers/BackupCodeLoginWrapper.tsx +0 -34
- package/src/wrappers/BackupCodesWrapper.tsx +0 -28
- package/src/wrappers/ChangePasswordFormWrapper.tsx +0 -34
- package/src/wrappers/ForgotPasswordFormWrapper.tsx +0 -45
- package/src/wrappers/LoginFormWrapper.tsx +0 -108
- package/src/wrappers/LogoutPageWrapper.tsx +0 -30
- package/src/wrappers/RegisterFormWrapper.tsx +0 -109
- package/src/wrappers/ResetPasswordFormWrapper.tsx +0 -57
- package/src/wrappers/UserSettingsFormWrapper.tsx +0 -140
- package/src/wrappers/VerifyEmailPageWrapper.tsx +0 -27
- package/src/wrappers/__tests__/LoginFormWrapper.totp.spec.tsx +0 -339
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthProvider = exports.useAuth = exports.AuthContext = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
6
|
+
const i18n_lib_1 = require("@digitaldefiance/i18n-lib");
|
|
7
|
+
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const auth_context_1 = require("./auth-context");
|
|
10
|
+
var auth_context_2 = require("./auth-context");
|
|
11
|
+
Object.defineProperty(exports, "AuthContext", { enumerable: true, get: function () { return auth_context_2.AuthContext; } });
|
|
12
|
+
Object.defineProperty(exports, "useAuth", { enumerable: true, get: function () { return auth_context_2.useAuth; } });
|
|
13
|
+
const useExpiringValue_1 = require("../hooks/useExpiringValue");
|
|
14
|
+
const useLocalStorage_1 = require("../hooks/useLocalStorage");
|
|
15
|
+
const useUserSettings_1 = require("../hooks/useUserSettings");
|
|
16
|
+
const authService_1 = require("../services/authService");
|
|
17
|
+
const authenticatedApi_1 = require("../services/authenticatedApi");
|
|
18
|
+
const I18nProvider_1 = require("./I18nProvider");
|
|
19
|
+
const ThemeProvider_1 = require("./ThemeProvider");
|
|
20
|
+
const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout, emailDomain, }) => {
|
|
21
|
+
const { tComponent, changeLanguage: i18nChangeLanguage } = (0, I18nProvider_1.useI18n)();
|
|
22
|
+
const { setColorMode: themeSetPaletteMode, mode: colorMode } = (0, ThemeProvider_1.useTheme)();
|
|
23
|
+
const authService = (0, react_1.useMemo)(() => (0, authService_1.createAuthService)(constants, baseUrl, eciesConfig, emailDomain), [constants, baseUrl, eciesConfig, emailDomain]);
|
|
24
|
+
const authenticatedApi = (0, react_1.useMemo)(() => (0, authenticatedApi_1.createAuthenticatedApiClient)(baseUrl), [baseUrl]);
|
|
25
|
+
// Use the custom hooks for expiring values
|
|
26
|
+
const mnemonicManager = (0, useExpiringValue_1.useExpiringValue)(constants.DefaultExpireMemoryMnemonicSeconds, 'mnemonicExpirationSeconds');
|
|
27
|
+
const walletManager = (0, useExpiringValue_1.useExpiringValue)(constants.DefaultExpireMemoryWalletSeconds, 'walletExpirationSeconds');
|
|
28
|
+
// Use localStorage hook for expiration settings
|
|
29
|
+
const [mnemonicExpirationSeconds, _setMnemonicExpirationSeconds] = (0, useLocalStorage_1.useLocalStorage)('mnemonicExpirationSeconds', constants.DefaultExpireMemoryMnemonicSeconds);
|
|
30
|
+
const [walletExpirationSeconds, _setWalletExpirationSeconds] = (0, useLocalStorage_1.useLocalStorage)('walletExpirationSeconds', constants.DefaultExpireMemoryWalletSeconds);
|
|
31
|
+
const [serverPublicKey, setServerPublicKey] = (0, react_1.useState)(null);
|
|
32
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
33
|
+
const [frontendUser, setFrontendUser] = (0, react_1.useState)(null);
|
|
34
|
+
const [isAuthenticated, setIsAuthenticated] = (0, react_1.useState)(false);
|
|
35
|
+
const [isGlobalAdmin, setIsGlobalAdmin] = (0, react_1.useState)(false);
|
|
36
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
37
|
+
// Separate flag so route guards don't unmount during actions (e.g., register/login)
|
|
38
|
+
const [isCheckingAuth, setIsCheckingAuth] = (0, react_1.useState)(true);
|
|
39
|
+
const [token, setToken] = (0, react_1.useState)(null);
|
|
40
|
+
const [authState, setAuthState] = (0, react_1.useState)(0);
|
|
41
|
+
// Use the user settings hook for settings management
|
|
42
|
+
const { userSettings, setUserSettingAndUpdateSettings } = (0, useUserSettings_1.useUserSettings)({
|
|
43
|
+
authenticatedApi,
|
|
44
|
+
isAuthenticated,
|
|
45
|
+
});
|
|
46
|
+
// Helper functions to calculate remaining time (now provided by the hooks)
|
|
47
|
+
const getMnemonicRemainingTime = mnemonicManager.getRemainingTime;
|
|
48
|
+
const getWalletRemainingTime = walletManager.getRemainingTime;
|
|
49
|
+
// Wrapper functions to match the interface (the localStorage hook handles storage automatically)
|
|
50
|
+
const setMnemonicExpirationSeconds = _setMnemonicExpirationSeconds;
|
|
51
|
+
const setWalletExpirationSeconds = _setWalletExpirationSeconds;
|
|
52
|
+
// Sync user language with i18n provider when the user's saved language changes.
|
|
53
|
+
// Only update the i18n engine — do NOT call setUserSettingAndUpdateSettings
|
|
54
|
+
// here because its merge with defaults can overwrite other settings (e.g.
|
|
55
|
+
// timezone) with default values when the closure captures stale userSettings.
|
|
56
|
+
(0, react_1.useEffect)(() => {
|
|
57
|
+
if (user?.siteLanguage) {
|
|
58
|
+
i18nChangeLanguage(user.siteLanguage);
|
|
59
|
+
}
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
+
}, [user?.siteLanguage]);
|
|
62
|
+
const setMnemonic = (0, react_1.useCallback)((mnemonic, durationSeconds) => {
|
|
63
|
+
const finalDurationSeconds = durationSeconds ?? mnemonicExpirationSeconds;
|
|
64
|
+
// Store the duration to localStorage if provided
|
|
65
|
+
if (durationSeconds !== undefined) {
|
|
66
|
+
_setMnemonicExpirationSeconds(durationSeconds);
|
|
67
|
+
}
|
|
68
|
+
// Only save to storage if a custom duration was provided
|
|
69
|
+
return mnemonicManager.setValue(mnemonic, finalDurationSeconds, durationSeconds !== undefined);
|
|
70
|
+
},
|
|
71
|
+
// mnemonicManager is intentionally excluded as it's a stable reference from useExpiringValue
|
|
72
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
+
[
|
|
74
|
+
mnemonicExpirationSeconds,
|
|
75
|
+
mnemonicManager.setValue,
|
|
76
|
+
_setMnemonicExpirationSeconds,
|
|
77
|
+
]);
|
|
78
|
+
const setWallet = (0, react_1.useCallback)((wallet, durationSeconds) => {
|
|
79
|
+
const finalDurationSeconds = durationSeconds ?? walletExpirationSeconds;
|
|
80
|
+
// Store the duration to localStorage if provided
|
|
81
|
+
if (durationSeconds !== undefined) {
|
|
82
|
+
_setWalletExpirationSeconds(durationSeconds);
|
|
83
|
+
}
|
|
84
|
+
// Only save to storage if a custom duration was provided
|
|
85
|
+
return walletManager.setValue(wallet, finalDurationSeconds, durationSeconds !== undefined);
|
|
86
|
+
},
|
|
87
|
+
// walletManager is intentionally excluded as it's a stable reference from useExpiringValue
|
|
88
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
|
+
[
|
|
90
|
+
walletExpirationSeconds,
|
|
91
|
+
walletManager.setValue,
|
|
92
|
+
_setWalletExpirationSeconds,
|
|
93
|
+
]);
|
|
94
|
+
const clearMnemonic = mnemonicManager.clearValue;
|
|
95
|
+
const clearWallet = walletManager.clearValue;
|
|
96
|
+
const checkAuth = (0, react_1.useCallback)(async () => {
|
|
97
|
+
const token = localStorage.getItem('authToken');
|
|
98
|
+
if (!token) {
|
|
99
|
+
setUser(null);
|
|
100
|
+
setIsAuthenticated(false);
|
|
101
|
+
setLoading(false);
|
|
102
|
+
setIsCheckingAuth(false);
|
|
103
|
+
setToken(null);
|
|
104
|
+
setFrontendUser(null);
|
|
105
|
+
setServerPublicKey(null);
|
|
106
|
+
await setUserSettingAndUpdateSettings(undefined);
|
|
107
|
+
themeSetPaletteMode('light');
|
|
108
|
+
clearMnemonic();
|
|
109
|
+
clearWallet();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const userData = await authService.verifyToken(token);
|
|
114
|
+
if ('error' in userData && typeof userData.error === 'string') {
|
|
115
|
+
setIsAuthenticated(false);
|
|
116
|
+
setToken(null);
|
|
117
|
+
}
|
|
118
|
+
else if ('id' in userData && 'email' in userData) {
|
|
119
|
+
const userDataDTO = userData;
|
|
120
|
+
setUser(userDataDTO);
|
|
121
|
+
setIsGlobalAdmin(userDataDTO.roles.some((r) => r.admin));
|
|
122
|
+
setIsAuthenticated(true);
|
|
123
|
+
setToken(token);
|
|
124
|
+
await setUserSettingAndUpdateSettings({
|
|
125
|
+
darkMode: userDataDTO.darkMode,
|
|
126
|
+
currency: new i18n_lib_1.CurrencyCode(userDataDTO.currency),
|
|
127
|
+
timezone: new i18n_lib_1.Timezone(userDataDTO.timezone),
|
|
128
|
+
siteLanguage: userDataDTO.siteLanguage,
|
|
129
|
+
email: new ecies_lib_1.EmailString(userDataDTO.email),
|
|
130
|
+
directChallenge: userDataDTO.directChallenge,
|
|
131
|
+
...(userDataDTO.displayName !== undefined
|
|
132
|
+
? { displayName: userDataDTO.displayName }
|
|
133
|
+
: {}),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error('Token verification failed:', error);
|
|
139
|
+
setUser(null);
|
|
140
|
+
setIsAuthenticated(false);
|
|
141
|
+
await setUserSettingAndUpdateSettings(undefined);
|
|
142
|
+
localStorage.removeItem('authToken');
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
setLoading(false);
|
|
146
|
+
setIsCheckingAuth(false);
|
|
147
|
+
}
|
|
148
|
+
}, [
|
|
149
|
+
authService,
|
|
150
|
+
clearMnemonic,
|
|
151
|
+
clearWallet,
|
|
152
|
+
setUserSettingAndUpdateSettings,
|
|
153
|
+
themeSetPaletteMode,
|
|
154
|
+
]);
|
|
155
|
+
(0, react_1.useEffect)(() => {
|
|
156
|
+
const token = localStorage.getItem('authToken');
|
|
157
|
+
if (token) {
|
|
158
|
+
(async () => {
|
|
159
|
+
await checkAuth();
|
|
160
|
+
})();
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
setLoading(false);
|
|
164
|
+
setIsCheckingAuth(false);
|
|
165
|
+
}
|
|
166
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
167
|
+
}, [authState]); // Only run when authState changes (login/logout), not when checkAuth is recreated
|
|
168
|
+
const directLogin = (0, react_1.useCallback)(async (mnemonic, username, email, expireMnemonicSeconds, expireWalletSeconds) => {
|
|
169
|
+
setLoading(true);
|
|
170
|
+
const loginResult = await authService.directLogin(mnemonic, username, email);
|
|
171
|
+
setLoading(false);
|
|
172
|
+
if (typeof loginResult === 'object' &&
|
|
173
|
+
'token' in loginResult &&
|
|
174
|
+
'user' in loginResult &&
|
|
175
|
+
'wallet' in loginResult) {
|
|
176
|
+
setMnemonic(mnemonic, expireMnemonicSeconds);
|
|
177
|
+
setUser(loginResult.user);
|
|
178
|
+
setWallet(loginResult.wallet, expireWalletSeconds);
|
|
179
|
+
setIsAuthenticated(true);
|
|
180
|
+
setAuthState((prev) => prev + 1);
|
|
181
|
+
localStorage.setItem('authToken', loginResult.token);
|
|
182
|
+
localStorage.setItem('user', JSON.stringify(loginResult.user));
|
|
183
|
+
await setUserSettingAndUpdateSettings({
|
|
184
|
+
darkMode: loginResult.user.darkMode,
|
|
185
|
+
currency: new i18n_lib_1.CurrencyCode(loginResult.user.currency),
|
|
186
|
+
timezone: new i18n_lib_1.Timezone(loginResult.user.timezone),
|
|
187
|
+
siteLanguage: loginResult.user.siteLanguage,
|
|
188
|
+
email: new ecies_lib_1.EmailString(loginResult.user.email),
|
|
189
|
+
directChallenge: loginResult.user.directChallenge,
|
|
190
|
+
...(loginResult.user.displayName !== undefined
|
|
191
|
+
? { displayName: loginResult.user.displayName }
|
|
192
|
+
: {}),
|
|
193
|
+
});
|
|
194
|
+
return loginResult;
|
|
195
|
+
}
|
|
196
|
+
return loginResult;
|
|
197
|
+
}, [authService, setMnemonic, setWallet, setUserSettingAndUpdateSettings]);
|
|
198
|
+
const emailChallengeLogin = (0, react_1.useCallback)(async (mnemonic, token, username, email, expireMnemonicSeconds, expireWalletSeconds) => {
|
|
199
|
+
setLoading(true);
|
|
200
|
+
const loginResult = await authService.emailChallengeLogin(mnemonic, token, username, email);
|
|
201
|
+
setLoading(false);
|
|
202
|
+
if (typeof loginResult === 'object' &&
|
|
203
|
+
'token' in loginResult &&
|
|
204
|
+
'user' in loginResult &&
|
|
205
|
+
'wallet' in loginResult) {
|
|
206
|
+
setMnemonic(mnemonic, expireMnemonicSeconds);
|
|
207
|
+
setUser(loginResult.user);
|
|
208
|
+
setWallet(loginResult.wallet, expireWalletSeconds);
|
|
209
|
+
setIsAuthenticated(true);
|
|
210
|
+
setAuthState((prev) => prev + 1);
|
|
211
|
+
localStorage.setItem('authToken', loginResult.token);
|
|
212
|
+
localStorage.setItem('user', JSON.stringify(loginResult.user));
|
|
213
|
+
await setUserSettingAndUpdateSettings({
|
|
214
|
+
darkMode: loginResult.user.darkMode,
|
|
215
|
+
currency: new i18n_lib_1.CurrencyCode(loginResult.user.currency),
|
|
216
|
+
timezone: new i18n_lib_1.Timezone(loginResult.user.timezone),
|
|
217
|
+
siteLanguage: loginResult.user.siteLanguage,
|
|
218
|
+
email: new ecies_lib_1.EmailString(loginResult.user.email),
|
|
219
|
+
directChallenge: loginResult.user.directChallenge,
|
|
220
|
+
...(loginResult.user.displayName !== undefined
|
|
221
|
+
? { displayName: loginResult.user.displayName }
|
|
222
|
+
: {}),
|
|
223
|
+
});
|
|
224
|
+
return loginResult;
|
|
225
|
+
}
|
|
226
|
+
return loginResult;
|
|
227
|
+
}, [authService, setMnemonic, setWallet, setUserSettingAndUpdateSettings]);
|
|
228
|
+
const getPasswordLoginService = (0, react_1.useCallback)(() => {
|
|
229
|
+
const eciesService = new ecies_lib_1.ECIESService(eciesConfig);
|
|
230
|
+
const aesGcmService = new ecies_lib_1.AESGCMService();
|
|
231
|
+
return new ecies_lib_1.PasswordLoginService(aesGcmService, eciesService, new ecies_lib_1.Pbkdf2Service(ecies_lib_1.Constants.PBKDF2_PROFILES, ecies_lib_1.Constants.ECIES, ecies_lib_1.Constants.PBKDF2));
|
|
232
|
+
}, [eciesConfig]);
|
|
233
|
+
const isBrowserPasswordLoginAvailable = (0, react_1.useCallback)(() => {
|
|
234
|
+
const storedEncryptedPrivateKey = localStorage.getItem(ecies_lib_1.PasswordLoginService.privateKeyStorageKey);
|
|
235
|
+
return !!storedEncryptedPrivateKey;
|
|
236
|
+
}, []);
|
|
237
|
+
const passwordLogin = (0, react_1.useCallback)(async (password, username, email) => {
|
|
238
|
+
if (!isBrowserPasswordLoginAvailable()) {
|
|
239
|
+
return {
|
|
240
|
+
error: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Error_Login_PasswordLoginNotSetup),
|
|
241
|
+
errorType: 'PasswordLoginNotSetup',
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
setLoading(true);
|
|
245
|
+
const passwordLoginService = getPasswordLoginService();
|
|
246
|
+
const { wallet, mnemonic } = await passwordLoginService.getWalletAndMnemonicFromLocalStorageBundle(password);
|
|
247
|
+
const loginResult = await authService.directLogin(mnemonic, username, email);
|
|
248
|
+
setLoading(false);
|
|
249
|
+
setWallet(wallet);
|
|
250
|
+
setMnemonic(mnemonic);
|
|
251
|
+
// Set theme based on user's darkMode preference if login succeeded
|
|
252
|
+
if ('user' in loginResult) {
|
|
253
|
+
await setUserSettingAndUpdateSettings({
|
|
254
|
+
darkMode: loginResult.user.darkMode,
|
|
255
|
+
currency: new i18n_lib_1.CurrencyCode(loginResult.user.currency),
|
|
256
|
+
timezone: new i18n_lib_1.Timezone(loginResult.user.timezone),
|
|
257
|
+
siteLanguage: loginResult.user.siteLanguage,
|
|
258
|
+
email: new ecies_lib_1.EmailString(loginResult.user.email),
|
|
259
|
+
directChallenge: loginResult.user.directChallenge,
|
|
260
|
+
...(loginResult.user.displayName !== undefined
|
|
261
|
+
? { displayName: loginResult.user.displayName }
|
|
262
|
+
: {}),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return loginResult;
|
|
266
|
+
}, [
|
|
267
|
+
authService,
|
|
268
|
+
getPasswordLoginService,
|
|
269
|
+
setMnemonic,
|
|
270
|
+
setWallet,
|
|
271
|
+
tComponent,
|
|
272
|
+
isBrowserPasswordLoginAvailable,
|
|
273
|
+
setUserSettingAndUpdateSettings,
|
|
274
|
+
]);
|
|
275
|
+
const refreshToken = (0, react_1.useCallback)(async () => {
|
|
276
|
+
try {
|
|
277
|
+
const result = await authService.refreshToken();
|
|
278
|
+
localStorage.setItem('authToken', result.token);
|
|
279
|
+
localStorage.setItem('user', JSON.stringify(result.user));
|
|
280
|
+
setUser(result.user);
|
|
281
|
+
setIsAuthenticated(true);
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
setUser(null);
|
|
286
|
+
setIsAuthenticated(false);
|
|
287
|
+
localStorage.removeItem('authToken');
|
|
288
|
+
localStorage.removeItem('user');
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
}, [authService]);
|
|
292
|
+
const register = (0, react_1.useCallback)(async (username, email, timezone, password, mnemonic, displayName, directChallenge) => {
|
|
293
|
+
const registerResult = await authService.register(username, email, timezone, password, mnemonic, displayName, directChallenge);
|
|
294
|
+
return registerResult;
|
|
295
|
+
}, [authService]);
|
|
296
|
+
const requestEmailLogin = (0, react_1.useCallback)(async (username, email) => {
|
|
297
|
+
setLoading(true);
|
|
298
|
+
const result = await authService.requestEmailLogin(username, email);
|
|
299
|
+
setLoading(false);
|
|
300
|
+
return result;
|
|
301
|
+
}, [authService]);
|
|
302
|
+
const setUpBrowserPasswordLogin = (0, react_1.useCallback)(async (mnemonic, password) => {
|
|
303
|
+
setLoading(true);
|
|
304
|
+
const passwordLoginService = getPasswordLoginService();
|
|
305
|
+
try {
|
|
306
|
+
const wallet = await passwordLoginService.setupPasswordLoginLocalStorageBundle(mnemonic, password);
|
|
307
|
+
setLoading(false);
|
|
308
|
+
setWallet(wallet);
|
|
309
|
+
setMnemonic(mnemonic);
|
|
310
|
+
return {
|
|
311
|
+
success: true,
|
|
312
|
+
message: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordLogin_Setup_Success),
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
setLoading(false);
|
|
317
|
+
return {
|
|
318
|
+
success: false,
|
|
319
|
+
message: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordLogin_Setup_Failure),
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}, [getPasswordLoginService, setMnemonic, setWallet, tComponent]);
|
|
323
|
+
const backupCodeLogin = (0, react_1.useCallback)(async (identifier, code, isEmail, recoverMnemonic, newPassword) => {
|
|
324
|
+
setLoading(true);
|
|
325
|
+
const loginResult = await authService.backupCodeLogin(identifier, code, isEmail, recoverMnemonic, newPassword);
|
|
326
|
+
setLoading(false);
|
|
327
|
+
if (typeof loginResult === 'object' && 'token' in loginResult) {
|
|
328
|
+
localStorage.setItem('authToken', loginResult.token);
|
|
329
|
+
if (loginResult.user) {
|
|
330
|
+
setUser(loginResult.user);
|
|
331
|
+
setIsAuthenticated(true);
|
|
332
|
+
await setUserSettingAndUpdateSettings({
|
|
333
|
+
darkMode: loginResult.user.darkMode,
|
|
334
|
+
currency: new i18n_lib_1.CurrencyCode(loginResult.user.currency),
|
|
335
|
+
timezone: new i18n_lib_1.Timezone(loginResult.user.timezone),
|
|
336
|
+
siteLanguage: loginResult.user.siteLanguage,
|
|
337
|
+
email: new ecies_lib_1.EmailString(loginResult.user.email),
|
|
338
|
+
directChallenge: loginResult.user.directChallenge,
|
|
339
|
+
...(loginResult.user.displayName !== undefined
|
|
340
|
+
? { displayName: loginResult.user.displayName }
|
|
341
|
+
: {}),
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
setAuthState((prev) => prev + 1);
|
|
345
|
+
return {
|
|
346
|
+
token: loginResult.token,
|
|
347
|
+
mnemonic: loginResult.mnemonic,
|
|
348
|
+
message: loginResult.message,
|
|
349
|
+
codeCount: loginResult.codeCount,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return loginResult;
|
|
353
|
+
}, [authService, setUserSettingAndUpdateSettings]);
|
|
354
|
+
const logout = (0, react_1.useCallback)(async () => {
|
|
355
|
+
localStorage.removeItem('user');
|
|
356
|
+
localStorage.removeItem('authToken');
|
|
357
|
+
clearMnemonic();
|
|
358
|
+
setUser(null);
|
|
359
|
+
clearWallet();
|
|
360
|
+
setIsAuthenticated(false);
|
|
361
|
+
await setUserSettingAndUpdateSettings(undefined);
|
|
362
|
+
setAuthState((prev) => prev + 1);
|
|
363
|
+
// Call the optional navigation callback if provided
|
|
364
|
+
if (onLogout) {
|
|
365
|
+
onLogout();
|
|
366
|
+
}
|
|
367
|
+
}, [onLogout, clearMnemonic, clearWallet, setUserSettingAndUpdateSettings]);
|
|
368
|
+
const verifyToken = (0, react_1.useCallback)(async (token) => {
|
|
369
|
+
const requestUser = await authService.verifyToken(token);
|
|
370
|
+
if (typeof requestUser === 'object' && 'error' in requestUser) {
|
|
371
|
+
setIsAuthenticated(false);
|
|
372
|
+
await setUserSettingAndUpdateSettings(undefined);
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
setUser(requestUser);
|
|
377
|
+
setIsAuthenticated(true);
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
}, [authService, setUserSettingAndUpdateSettings]);
|
|
381
|
+
const changePassword = (0, react_1.useCallback)(async (currentPassword, newPassword) => {
|
|
382
|
+
if (!isBrowserPasswordLoginAvailable()) {
|
|
383
|
+
return {
|
|
384
|
+
error: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Error_Login_PasswordLoginNotSetup),
|
|
385
|
+
errorType: 'PasswordLoginNotSetup',
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
setLoading(true);
|
|
389
|
+
try {
|
|
390
|
+
const passwordLoginService = getPasswordLoginService();
|
|
391
|
+
const { mnemonic, wallet } = await passwordLoginService.getWalletAndMnemonicFromLocalStorageBundle(new ecies_lib_1.SecureString(currentPassword));
|
|
392
|
+
if (!mnemonic) {
|
|
393
|
+
setLoading(false);
|
|
394
|
+
return {
|
|
395
|
+
error: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordLogin_InvalidCurrentPassword),
|
|
396
|
+
errorType: 'InvalidCurrentPassword',
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
await passwordLoginService.setupPasswordLoginLocalStorageBundle(mnemonic, new ecies_lib_1.SecureString(newPassword));
|
|
400
|
+
setLoading(false);
|
|
401
|
+
setWallet(wallet);
|
|
402
|
+
setMnemonic(mnemonic);
|
|
403
|
+
return {
|
|
404
|
+
success: true,
|
|
405
|
+
message: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordChange_Success),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
setLoading(false);
|
|
410
|
+
return { error: 'Password change failed' };
|
|
411
|
+
}
|
|
412
|
+
}, [
|
|
413
|
+
getPasswordLoginService,
|
|
414
|
+
setMnemonic,
|
|
415
|
+
setWallet,
|
|
416
|
+
tComponent,
|
|
417
|
+
isBrowserPasswordLoginAvailable,
|
|
418
|
+
]);
|
|
419
|
+
const contextValue = (0, react_1.useMemo)(() => {
|
|
420
|
+
const setUserAndIsAuthenticated = async (newUser) => {
|
|
421
|
+
setUser(newUser);
|
|
422
|
+
setIsAuthenticated(!!newUser);
|
|
423
|
+
};
|
|
424
|
+
return {
|
|
425
|
+
admin: isGlobalAdmin,
|
|
426
|
+
authState,
|
|
427
|
+
backupCodeLogin,
|
|
428
|
+
changePassword,
|
|
429
|
+
checkAuth,
|
|
430
|
+
clearMnemonic,
|
|
431
|
+
clearWallet,
|
|
432
|
+
colorMode,
|
|
433
|
+
currencyCode: userSettings?.currency,
|
|
434
|
+
directLogin,
|
|
435
|
+
emailChallengeLogin,
|
|
436
|
+
getMnemonicRemainingTime,
|
|
437
|
+
getWalletRemainingTime,
|
|
438
|
+
isAuthenticated,
|
|
439
|
+
isCheckingAuth,
|
|
440
|
+
isBrowserPasswordLoginAvailable,
|
|
441
|
+
loading,
|
|
442
|
+
logout,
|
|
443
|
+
mnemonic: mnemonicManager.value,
|
|
444
|
+
mnemonicExpirationSeconds,
|
|
445
|
+
passwordLogin,
|
|
446
|
+
refreshToken,
|
|
447
|
+
register,
|
|
448
|
+
requestEmailLogin,
|
|
449
|
+
serverPublicKey,
|
|
450
|
+
setMnemonic,
|
|
451
|
+
setMnemonicExpirationSeconds,
|
|
452
|
+
setUpBrowserPasswordLogin,
|
|
453
|
+
setUser: setUserAndIsAuthenticated,
|
|
454
|
+
setUserSetting: setUserSettingAndUpdateSettings,
|
|
455
|
+
setWallet,
|
|
456
|
+
setWalletExpirationSeconds,
|
|
457
|
+
setupTotp: () => authService.setupTotp(),
|
|
458
|
+
confirmTotp: (code) => authService.confirmTotp(code),
|
|
459
|
+
verifyTotpLogin: (pendingTotpToken, code) => authService.verifyTotpLogin(pendingTotpToken, code),
|
|
460
|
+
token,
|
|
461
|
+
user: frontendUser,
|
|
462
|
+
userData: user,
|
|
463
|
+
userSettings,
|
|
464
|
+
verifyToken,
|
|
465
|
+
wallet: walletManager.value,
|
|
466
|
+
walletExpirationSeconds,
|
|
467
|
+
};
|
|
468
|
+
// authenticatedApi is intentionally excluded as it's a stable reference from useMemo
|
|
469
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
470
|
+
}, [
|
|
471
|
+
authState,
|
|
472
|
+
backupCodeLogin,
|
|
473
|
+
changePassword,
|
|
474
|
+
checkAuth,
|
|
475
|
+
clearMnemonic,
|
|
476
|
+
clearWallet,
|
|
477
|
+
colorMode,
|
|
478
|
+
directLogin,
|
|
479
|
+
emailChallengeLogin,
|
|
480
|
+
frontendUser,
|
|
481
|
+
getMnemonicRemainingTime,
|
|
482
|
+
getWalletRemainingTime,
|
|
483
|
+
isAuthenticated,
|
|
484
|
+
isCheckingAuth,
|
|
485
|
+
isGlobalAdmin,
|
|
486
|
+
isBrowserPasswordLoginAvailable,
|
|
487
|
+
loading,
|
|
488
|
+
logout,
|
|
489
|
+
mnemonicManager.value,
|
|
490
|
+
mnemonicExpirationSeconds,
|
|
491
|
+
passwordLogin,
|
|
492
|
+
refreshToken,
|
|
493
|
+
register,
|
|
494
|
+
requestEmailLogin,
|
|
495
|
+
serverPublicKey,
|
|
496
|
+
setMnemonic,
|
|
497
|
+
setMnemonicExpirationSeconds,
|
|
498
|
+
setUpBrowserPasswordLogin,
|
|
499
|
+
setUserSettingAndUpdateSettings,
|
|
500
|
+
setWallet,
|
|
501
|
+
setWalletExpirationSeconds,
|
|
502
|
+
token,
|
|
503
|
+
user,
|
|
504
|
+
userSettings,
|
|
505
|
+
verifyToken,
|
|
506
|
+
walletManager.value,
|
|
507
|
+
walletExpirationSeconds,
|
|
508
|
+
]);
|
|
509
|
+
return ((0, jsx_runtime_1.jsx)(auth_context_1.AuthContext.Provider, { value: contextValue, children: children }));
|
|
510
|
+
};
|
|
511
|
+
const AuthProvider = ({ children, baseUrl, constants, eciesConfig, onLogout, emailDomain, }) => {
|
|
512
|
+
return ((0, jsx_runtime_1.jsx)(AuthProviderInner, { baseUrl: baseUrl, constants: constants, eciesConfig: eciesConfig, onLogout: onLogout, emailDomain: emailDomain, children: children }));
|
|
513
|
+
};
|
|
514
|
+
exports.AuthProvider = AuthProvider;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal structural interface accepted by I18nProvider.
|
|
4
|
+
* Both I18nEngine and PluginI18nEngine satisfy this interface.
|
|
5
|
+
*/
|
|
6
|
+
export interface II18nEngineCompat {
|
|
7
|
+
setLanguage(language: string): void;
|
|
8
|
+
translate(componentId: string, stringKey: string, variables?: Record<string, string | number>, language?: string): string;
|
|
9
|
+
translateStringKey?(key: string, vars?: Record<string, string | number>, language?: string): string;
|
|
10
|
+
/** Template processor that handles {{component.key}} and {variable} patterns */
|
|
11
|
+
t?(template: string, variables?: Record<string, string | number>, language?: string): string;
|
|
12
|
+
}
|
|
13
|
+
export interface I18nProviderProps {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
i18nEngine: II18nEngineCompat;
|
|
16
|
+
onLanguageChange?: (language: string) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface I18nContextType {
|
|
19
|
+
t: (key: string, vars?: Record<string, string | number>, language?: string) => string;
|
|
20
|
+
tBranded: <TStringKey extends string>(stringKey: TStringKey, vars?: Record<string, string | number>, language?: string) => string;
|
|
21
|
+
tComponent: <TStringKey extends string>(componentId: string, stringKey: TStringKey, vars?: Record<string, string | number>, language?: string) => string;
|
|
22
|
+
changeLanguage: (language: string) => void;
|
|
23
|
+
currentLanguage: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const I18nProvider: FC<I18nProviderProps>;
|
|
26
|
+
export declare const useI18n: () => I18nContextType;
|
|
27
|
+
//# sourceMappingURL=I18nProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18nProvider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/I18nProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,EAEL,EAAE,EACF,SAAS,EAIV,MAAM,OAAO,CAAC;AAEf;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,SAAS,CACP,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC3C,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAAC;IACV,kBAAkB,CAAC,CACjB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACtC,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAAC;IACV,gFAAgF;IAChF,CAAC,CAAC,CACA,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC3C,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAAC;CACX;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAED,MAAM,WAAW,eAAe;IAC9B,CAAC,EAAE,CACD,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACtC,QAAQ,CAAC,EAAE,MAAM,KACd,MAAM,CAAC;IACZ,QAAQ,EAAE,CAAC,UAAU,SAAS,MAAM,EAClC,SAAS,EAAE,UAAU,EACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACtC,QAAQ,CAAC,EAAE,MAAM,KACd,MAAM,CAAC;IACZ,UAAU,EAAE,CAAC,UAAU,SAAS,MAAM,EACpC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,UAAU,EACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACtC,QAAQ,CAAC,EAAE,MAAM,KACd,MAAM,CAAC;IACZ,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,eAAe,EAAE,MAAM,CAAC;CACzB;AAID,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAuF9C,CAAC;AAEF,eAAO,MAAM,OAAO,uBAMnB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useI18n = exports.I18nProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const i18n_lib_1 = require("@digitaldefiance/i18n-lib");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const I18nContext = (0, react_1.createContext)(undefined);
|
|
8
|
+
const I18nProvider = ({ children, i18nEngine, onLanguageChange, }) => {
|
|
9
|
+
const context = i18n_lib_1.GlobalActiveContext.getInstance();
|
|
10
|
+
const [currentLanguage, setCurrentLanguage] = (0, react_1.useState)(context.userLanguage);
|
|
11
|
+
const changeLanguage = (0, react_1.useCallback)(async (language) => {
|
|
12
|
+
const languageDetails = i18n_lib_1.LanguageRegistry.getLanguageByCode(language);
|
|
13
|
+
if (language && languageDetails) {
|
|
14
|
+
context.userLanguage = language;
|
|
15
|
+
i18nEngine.setLanguage(language);
|
|
16
|
+
localStorage.setItem('language', languageDetails.name);
|
|
17
|
+
localStorage.setItem('languageCode', language);
|
|
18
|
+
setCurrentLanguage(language);
|
|
19
|
+
if (onLanguageChange) {
|
|
20
|
+
await onLanguageChange(language);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, [onLanguageChange, i18nEngine, context]);
|
|
24
|
+
const tBranded = (0, react_1.useCallback)((key, vars, language) => {
|
|
25
|
+
if (!i18nEngine.translateStringKey)
|
|
26
|
+
return `[${key}]`;
|
|
27
|
+
return i18nEngine.translateStringKey(key, vars, language ?? currentLanguage);
|
|
28
|
+
}, [i18nEngine, currentLanguage]);
|
|
29
|
+
const t = (0, react_1.useCallback)((key, vars, language) => {
|
|
30
|
+
// If the engine has a template processor and the key looks like a template
|
|
31
|
+
// (contains {{...}} or {variable} patterns), use t() for template resolution
|
|
32
|
+
if (i18nEngine.t && (/\{\{/.test(key) || /\{[A-Za-z]/.test(key))) {
|
|
33
|
+
return i18nEngine.t(key, vars, language ?? currentLanguage);
|
|
34
|
+
}
|
|
35
|
+
if (i18nEngine.translateStringKey) {
|
|
36
|
+
return i18nEngine.translateStringKey(key, vars, language ?? currentLanguage);
|
|
37
|
+
}
|
|
38
|
+
return `[${key}]`;
|
|
39
|
+
}, [i18nEngine, currentLanguage]);
|
|
40
|
+
const tComponent = (0, react_1.useCallback)((componentId, stringKey, vars, language) => {
|
|
41
|
+
return i18nEngine.translate(componentId, stringKey, vars, language ?? currentLanguage);
|
|
42
|
+
}, [currentLanguage, i18nEngine]);
|
|
43
|
+
const value = {
|
|
44
|
+
t,
|
|
45
|
+
tComponent,
|
|
46
|
+
tBranded,
|
|
47
|
+
changeLanguage,
|
|
48
|
+
currentLanguage,
|
|
49
|
+
};
|
|
50
|
+
return (0, jsx_runtime_1.jsx)(I18nContext.Provider, { value: value, children: children });
|
|
51
|
+
};
|
|
52
|
+
exports.I18nProvider = I18nProvider;
|
|
53
|
+
const useI18n = () => {
|
|
54
|
+
const context = (0, react_1.useContext)(I18nContext);
|
|
55
|
+
if (context === undefined) {
|
|
56
|
+
throw new Error('useI18n must be used within an I18nProvider');
|
|
57
|
+
}
|
|
58
|
+
return context;
|
|
59
|
+
};
|
|
60
|
+
exports.useI18n = useI18n;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { IMenuConfig } from '../interfaces/IMenuConfig';
|
|
3
|
+
import { IMenuOption } from '../interfaces/IMenuOption';
|
|
4
|
+
import { MenuType } from '../types/MenuType';
|
|
5
|
+
interface MenuProviderProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
menuConfigs?: IMenuConfig[];
|
|
8
|
+
enableBackupCodes?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* IDs of menu options to suppress from every menu. Matches both the built-in
|
|
11
|
+
* options (e.g. 'change-password', 'user-settings', 'logout') and any option
|
|
12
|
+
* registered via `menuConfigs`. Dividers left orphaned by the removal are
|
|
13
|
+
* cleaned up automatically. Defaults to none hidden, so existing consumers are
|
|
14
|
+
* unaffected.
|
|
15
|
+
*/
|
|
16
|
+
hiddenMenuIds?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
interface MenuContextType {
|
|
19
|
+
menuOptions: IMenuOption[];
|
|
20
|
+
getMenuOptions: (menuType: MenuType, includeDividers: boolean) => IMenuOption[];
|
|
21
|
+
registerMenuOption: (option: IMenuOption) => () => void;
|
|
22
|
+
registerMenuOptions: (options: IMenuOption[]) => () => void;
|
|
23
|
+
getTopMenus: () => Array<IMenuConfig>;
|
|
24
|
+
}
|
|
25
|
+
export declare const MenuProvider: FC<MenuProviderProps>;
|
|
26
|
+
export declare const useMenu: () => MenuContextType;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=MenuContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MenuContext.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/MenuContext.tsx"],"names":[],"mappings":"AAqBA,OAAO,EACL,EAAE,EACF,SAAS,EAQV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAa,MAAM,mBAAmB,CAAC;AAMxD,UAAU,iBAAiB;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,UAAU,eAAe;IACvB,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,cAAc,EAAE,CACd,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,OAAO,KACrB,WAAW,EAAE,CAAC;IACnB,kBAAkB,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,MAAM,IAAI,CAAC;IACxD,mBAAmB,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,MAAM,IAAI,CAAC;IAC5D,WAAW,EAAE,MAAM,KAAK,CAAC,WAAW,CAAC,CAAC;CACvC;AAID,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAwW9C,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,eAM1B,CAAC"}
|