@digitaldefiance/express-suite-react-components 5.0.1 → 5.0.2
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/LICENSE +21 -0
- package/package.json +3 -4
- package/src/auth/AdminRoute.tsx +54 -0
- package/src/auth/Private.tsx +17 -0
- package/src/auth/PrivateRoute.tsx +28 -0
- package/src/auth/UnAuth.tsx +16 -0
- package/src/auth/UnAuthRoute.tsx +30 -0
- package/src/auth/{index.d.ts → index.ts} +2 -3
- package/src/components/ApiAccess.tsx +175 -0
- package/src/components/BackupCodeLoginForm.tsx +489 -0
- package/src/components/BackupCodesForm.tsx +287 -0
- package/src/components/CategoryMenu.tsx +155 -0
- package/src/components/ChangePasswordForm.tsx +273 -0
- package/src/components/ConfirmationDialog.tsx +48 -0
- package/src/components/CurrencyCodeSelector.tsx +60 -0
- package/src/components/CurrencyInput.tsx +80 -0
- package/src/components/DashboardPage.tsx +24 -0
- package/src/components/DropdownMenu.tsx +105 -0
- package/src/components/ExpirationSecondsSelector.tsx +60 -0
- package/src/components/FakeEmailAdminPanel.tsx +374 -0
- package/src/components/Flag.tsx +52 -0
- package/src/components/ForgotPasswordForm.tsx +174 -0
- package/src/components/LoginForm.tsx +468 -0
- package/src/components/LogoutPage.tsx +21 -0
- package/src/components/RegisterForm.tsx +1169 -0
- package/src/components/ResetPasswordForm.tsx +247 -0
- package/src/components/SideMenu.tsx +46 -0
- package/src/components/SideMenuListItem.tsx +75 -0
- package/src/components/T.tsx +24 -0
- package/src/components/TDiv.tsx +26 -0
- package/src/components/TImgAlt.tsx +28 -0
- package/src/components/TopMenu.tsx +252 -0
- package/src/components/TotpSetupForm.tsx +188 -0
- package/src/components/TotpVerificationForm.tsx +148 -0
- package/src/components/TranslatedTitle.tsx +31 -0
- package/src/components/UserLanguageSelector.tsx +45 -0
- package/src/components/UserMenu.tsx +15 -0
- package/src/components/UserSettingsForm.tsx +904 -0
- package/src/components/VerifyEmailPage.tsx +222 -0
- package/src/components/__tests__/RegisterForm.totp.spec.tsx +377 -0
- package/src/components/__tests__/TotpSetupForm.spec.tsx +258 -0
- package/src/components/__tests__/TotpVerificationForm.spec.tsx +259 -0
- package/src/components/__tests__/UserSettingsForm.totp.spec.tsx +396 -0
- package/src/components/{index.d.ts → index.ts} +1 -1
- package/src/contexts/AuthProvider.spec.tsx +1284 -0
- package/src/contexts/AuthProvider.tsx +977 -0
- package/src/contexts/I18nProvider.tsx +164 -0
- package/src/contexts/MenuContext.tsx +426 -0
- package/src/contexts/SuiteConfigProvider.tsx +93 -0
- package/src/contexts/ThemeProvider.tsx +67 -0
- package/src/contexts/{index.d.ts → index.ts} +0 -1
- package/src/hooks/{index.d.ts → index.ts} +0 -1
- package/src/hooks/useAuthenticatedApi.tsx +67 -0
- package/src/hooks/useBackupCodes.ts +105 -0
- package/src/hooks/useEmailVerification.ts +54 -0
- package/src/hooks/useExpiringValue.ts +78 -0
- package/src/hooks/useLocalStorage.ts +18 -0
- package/src/hooks/useUserSettings.ts +271 -0
- package/src/{index.d.ts → index.ts} +1 -1
- package/src/interfaces/IAppConfig.ts +7 -0
- package/src/interfaces/ICategoryConfig.ts +41 -0
- package/src/interfaces/IMenuConfig.ts +28 -0
- package/src/interfaces/IMenuOption.ts +79 -0
- package/src/interfaces/{index.d.ts → index.ts} +0 -1
- package/src/services/__mocks__/authService.ts +14 -0
- package/src/services/__tests__/authService.totp.property.spec.ts +360 -0
- package/src/services/__tests__/authService.totp.spec.ts +439 -0
- package/src/services/api.ts +13 -0
- package/src/services/authService.ts +692 -0
- package/src/services/authenticatedApi.ts +17 -0
- package/src/services/index.ts +3 -0
- package/src/types/MenuType.ts +15 -0
- package/src/types/expirationSeconds.ts +18 -0
- package/src/types/index.ts +1 -0
- package/src/types/translation.ts +20 -0
- package/src/wrappers/BackupCodeLoginWrapper.tsx +34 -0
- package/src/wrappers/BackupCodesWrapper.tsx +28 -0
- package/src/wrappers/ChangePasswordFormWrapper.tsx +34 -0
- package/src/wrappers/ForgotPasswordFormWrapper.tsx +45 -0
- package/src/wrappers/LoginFormWrapper.tsx +108 -0
- package/src/wrappers/LogoutPageWrapper.tsx +30 -0
- package/src/wrappers/RegisterFormWrapper.tsx +109 -0
- package/src/wrappers/ResetPasswordFormWrapper.tsx +57 -0
- package/src/wrappers/UserSettingsFormWrapper.tsx +140 -0
- package/src/wrappers/VerifyEmailPageWrapper.tsx +27 -0
- package/src/wrappers/__tests__/LoginFormWrapper.totp.spec.tsx +339 -0
- package/src/wrappers/{index.d.ts → index.tsx} +10 -1
- package/src/auth/AdminRoute.d.ts +0 -8
- package/src/auth/AdminRoute.d.ts.map +0 -1
- package/src/auth/AdminRoute.js +0 -28
- package/src/auth/Private.d.ts +0 -6
- package/src/auth/Private.d.ts.map +0 -1
- package/src/auth/Private.js +0 -14
- package/src/auth/PrivateRoute.d.ts +0 -8
- package/src/auth/PrivateRoute.d.ts.map +0 -1
- package/src/auth/PrivateRoute.js +0 -23
- package/src/auth/UnAuth.d.ts +0 -6
- package/src/auth/UnAuth.d.ts.map +0 -1
- package/src/auth/UnAuth.js +0 -14
- package/src/auth/UnAuthRoute.d.ts +0 -8
- package/src/auth/UnAuthRoute.d.ts.map +0 -1
- package/src/auth/UnAuthRoute.js +0 -22
- package/src/auth/index.d.ts.map +0 -1
- package/src/auth/index.js +0 -12
- package/src/components/ApiAccess.d.ts +0 -16
- package/src/components/ApiAccess.d.ts.map +0 -1
- package/src/components/ApiAccess.js +0 -77
- package/src/components/BackupCodeLoginForm.d.ts +0 -43
- package/src/components/BackupCodeLoginForm.d.ts.map +0 -1
- package/src/components/BackupCodeLoginForm.js +0 -139
- package/src/components/BackupCodesForm.d.ts +0 -26
- package/src/components/BackupCodesForm.d.ts.map +0 -1
- package/src/components/BackupCodesForm.js +0 -120
- package/src/components/CategoryMenu.d.ts +0 -17
- package/src/components/CategoryMenu.d.ts.map +0 -1
- package/src/components/CategoryMenu.js +0 -65
- package/src/components/ChangePasswordForm.d.ts +0 -26
- package/src/components/ChangePasswordForm.d.ts.map +0 -1
- package/src/components/ChangePasswordForm.js +0 -78
- package/src/components/ConfirmationDialog.d.ts +0 -13
- package/src/components/ConfirmationDialog.d.ts.map +0 -1
- package/src/components/ConfirmationDialog.js +0 -10
- package/src/components/CurrencyCodeSelector.d.ts +0 -9
- package/src/components/CurrencyCodeSelector.d.ts.map +0 -1
- package/src/components/CurrencyCodeSelector.js +0 -31
- package/src/components/CurrencyInput.d.ts +0 -13
- package/src/components/CurrencyInput.d.ts.map +0 -1
- package/src/components/CurrencyInput.js +0 -22
- package/src/components/DashboardPage.d.ts +0 -8
- package/src/components/DashboardPage.d.ts.map +0 -1
- package/src/components/DashboardPage.js +0 -10
- package/src/components/DropdownMenu.d.ts +0 -13
- package/src/components/DropdownMenu.d.ts.map +0 -1
- package/src/components/DropdownMenu.js +0 -63
- package/src/components/ExpirationSecondsSelector.d.ts +0 -13
- package/src/components/ExpirationSecondsSelector.d.ts.map +0 -1
- package/src/components/ExpirationSecondsSelector.js +0 -32
- package/src/components/FakeEmailAdminPanel.d.ts +0 -23
- package/src/components/FakeEmailAdminPanel.d.ts.map +0 -1
- package/src/components/FakeEmailAdminPanel.js +0 -147
- package/src/components/Flag.d.ts +0 -20
- package/src/components/Flag.d.ts.map +0 -1
- package/src/components/Flag.js +0 -43
- package/src/components/ForgotPasswordForm.d.ts +0 -18
- package/src/components/ForgotPasswordForm.d.ts.map +0 -1
- package/src/components/ForgotPasswordForm.js +0 -61
- package/src/components/LoginForm.d.ts +0 -44
- package/src/components/LoginForm.d.ts.map +0 -1
- package/src/components/LoginForm.js +0 -123
- package/src/components/LogoutPage.d.ts +0 -8
- package/src/components/LogoutPage.d.ts.map +0 -1
- package/src/components/LogoutPage.js +0 -16
- package/src/components/RegisterForm.d.ts +0 -100
- package/src/components/RegisterForm.d.ts.map +0 -1
- package/src/components/RegisterForm.js +0 -306
- package/src/components/ResetPasswordForm.d.ts +0 -23
- package/src/components/ResetPasswordForm.d.ts.map +0 -1
- package/src/components/ResetPasswordForm.js +0 -78
- package/src/components/SideMenu.d.ts +0 -8
- package/src/components/SideMenu.d.ts.map +0 -1
- package/src/components/SideMenu.js +0 -25
- package/src/components/SideMenuListItem.d.ts +0 -13
- package/src/components/SideMenuListItem.d.ts.map +0 -1
- package/src/components/SideMenuListItem.js +0 -44
- package/src/components/T.d.ts +0 -7
- package/src/components/T.d.ts.map +0 -1
- package/src/components/T.js +0 -13
- package/src/components/TDiv.d.ts +0 -9
- package/src/components/TDiv.d.ts.map +0 -1
- package/src/components/TDiv.js +0 -14
- package/src/components/TImgAlt.d.ts +0 -10
- package/src/components/TImgAlt.d.ts.map +0 -1
- package/src/components/TImgAlt.js +0 -14
- package/src/components/TopMenu.d.ts +0 -50
- package/src/components/TopMenu.d.ts.map +0 -1
- package/src/components/TopMenu.js +0 -79
- package/src/components/TotpSetupForm.d.ts +0 -24
- package/src/components/TotpSetupForm.d.ts.map +0 -1
- package/src/components/TotpSetupForm.js +0 -82
- package/src/components/TotpVerificationForm.d.ts +0 -23
- package/src/components/TotpVerificationForm.d.ts.map +0 -1
- package/src/components/TotpVerificationForm.js +0 -66
- package/src/components/TranslatedTitle.d.ts +0 -8
- package/src/components/TranslatedTitle.d.ts.map +0 -1
- package/src/components/TranslatedTitle.js +0 -15
- package/src/components/UserLanguageSelector.d.ts +0 -4
- package/src/components/UserLanguageSelector.d.ts.map +0 -1
- package/src/components/UserLanguageSelector.js +0 -31
- package/src/components/UserMenu.d.ts +0 -4
- package/src/components/UserMenu.d.ts.map +0 -1
- package/src/components/UserMenu.js +0 -12
- package/src/components/UserSettingsForm.d.ts +0 -113
- package/src/components/UserSettingsForm.d.ts.map +0 -1
- package/src/components/UserSettingsForm.js +0 -269
- package/src/components/VerifyEmailPage.d.ts +0 -24
- package/src/components/VerifyEmailPage.d.ts.map +0 -1
- package/src/components/VerifyEmailPage.js +0 -81
- package/src/components/index.d.ts.map +0 -1
- package/src/components/index.js +0 -35
- package/src/contexts/AuthProvider.d.ts +0 -186
- package/src/contexts/AuthProvider.d.ts.map +0 -1
- package/src/contexts/AuthProvider.js +0 -515
- package/src/contexts/I18nProvider.d.ts +0 -27
- package/src/contexts/I18nProvider.d.ts.map +0 -1
- package/src/contexts/I18nProvider.js +0 -60
- package/src/contexts/MenuContext.d.ts +0 -20
- package/src/contexts/MenuContext.d.ts.map +0 -1
- package/src/contexts/MenuContext.js +0 -275
- package/src/contexts/SuiteConfigProvider.d.ts +0 -44
- package/src/contexts/SuiteConfigProvider.d.ts.map +0 -1
- package/src/contexts/SuiteConfigProvider.js +0 -43
- package/src/contexts/ThemeProvider.d.ts +0 -15
- package/src/contexts/ThemeProvider.d.ts.map +0 -1
- package/src/contexts/ThemeProvider.js +0 -36
- package/src/contexts/index.d.ts.map +0 -1
- package/src/contexts/index.js +0 -8
- package/src/hooks/index.d.ts.map +0 -1
- package/src/hooks/index.js +0 -9
- package/src/hooks/useAuthenticatedApi.d.ts +0 -34
- package/src/hooks/useAuthenticatedApi.d.ts.map +0 -1
- package/src/hooks/useAuthenticatedApi.js +0 -46
- package/src/hooks/useBackupCodes.d.ts +0 -15
- package/src/hooks/useBackupCodes.d.ts.map +0 -1
- package/src/hooks/useBackupCodes.js +0 -74
- package/src/hooks/useEmailVerification.d.ts +0 -10
- package/src/hooks/useEmailVerification.d.ts.map +0 -1
- package/src/hooks/useEmailVerification.js +0 -40
- package/src/hooks/useExpiringValue.d.ts +0 -14
- package/src/hooks/useExpiringValue.d.ts.map +0 -1
- package/src/hooks/useExpiringValue.js +0 -53
- package/src/hooks/useLocalStorage.d.ts +0 -2
- package/src/hooks/useLocalStorage.d.ts.map +0 -1
- package/src/hooks/useLocalStorage.js +0 -15
- package/src/hooks/useUserSettings.d.ts +0 -48
- package/src/hooks/useUserSettings.d.ts.map +0 -1
- package/src/hooks/useUserSettings.js +0 -171
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -12
- package/src/interfaces/IAppConfig.d.ts +0 -8
- package/src/interfaces/IAppConfig.d.ts.map +0 -1
- package/src/interfaces/IAppConfig.js +0 -2
- package/src/interfaces/ICategoryConfig.d.ts +0 -41
- package/src/interfaces/ICategoryConfig.d.ts.map +0 -1
- package/src/interfaces/ICategoryConfig.js +0 -2
- package/src/interfaces/IMenuConfig.d.ts +0 -28
- package/src/interfaces/IMenuConfig.d.ts.map +0 -1
- package/src/interfaces/IMenuConfig.js +0 -2
- package/src/interfaces/IMenuOption.d.ts +0 -82
- package/src/interfaces/IMenuOption.d.ts.map +0 -1
- package/src/interfaces/IMenuOption.js +0 -2
- package/src/interfaces/index.d.ts.map +0 -1
- package/src/interfaces/index.js +0 -7
- package/src/services/__mocks__/authService.d.ts +0 -21
- package/src/services/__mocks__/authService.d.ts.map +0 -1
- package/src/services/__mocks__/authService.js +0 -15
- package/src/services/api.d.ts +0 -3
- package/src/services/api.d.ts.map +0 -1
- package/src/services/api.js +0 -14
- package/src/services/authService.d.ts +0 -126
- package/src/services/authService.d.ts.map +0 -1
- package/src/services/authService.js +0 -471
- package/src/services/authenticatedApi.d.ts +0 -3
- package/src/services/authenticatedApi.d.ts.map +0 -1
- package/src/services/authenticatedApi.js +0 -18
- package/src/services/index.d.ts +0 -4
- package/src/services/index.d.ts.map +0 -1
- package/src/services/index.js +0 -6
- package/src/types/MenuType.d.ts +0 -11
- package/src/types/MenuType.d.ts.map +0 -1
- package/src/types/MenuType.js +0 -12
- package/src/types/expirationSeconds.d.ts +0 -3
- package/src/types/expirationSeconds.d.ts.map +0 -1
- package/src/types/expirationSeconds.js +0 -17
- package/src/types/index.d.ts +0 -2
- package/src/types/index.d.ts.map +0 -1
- package/src/types/index.js +0 -4
- package/src/types/translation.d.ts +0 -10
- package/src/types/translation.d.ts.map +0 -1
- package/src/types/translation.js +0 -9
- package/src/wrappers/BackupCodeLoginWrapper.d.ts +0 -8
- package/src/wrappers/BackupCodeLoginWrapper.d.ts.map +0 -1
- package/src/wrappers/BackupCodeLoginWrapper.js +0 -20
- package/src/wrappers/BackupCodesWrapper.d.ts +0 -7
- package/src/wrappers/BackupCodesWrapper.d.ts.map +0 -1
- package/src/wrappers/BackupCodesWrapper.js +0 -17
- package/src/wrappers/ChangePasswordFormWrapper.d.ts +0 -8
- package/src/wrappers/ChangePasswordFormWrapper.d.ts.map +0 -1
- package/src/wrappers/ChangePasswordFormWrapper.js +0 -21
- package/src/wrappers/ForgotPasswordFormWrapper.d.ts +0 -8
- package/src/wrappers/ForgotPasswordFormWrapper.d.ts.map +0 -1
- package/src/wrappers/ForgotPasswordFormWrapper.js +0 -29
- package/src/wrappers/LoginFormWrapper.d.ts +0 -21
- package/src/wrappers/LoginFormWrapper.d.ts.map +0 -1
- package/src/wrappers/LoginFormWrapper.js +0 -72
- package/src/wrappers/LogoutPageWrapper.d.ts +0 -9
- package/src/wrappers/LogoutPageWrapper.d.ts.map +0 -1
- package/src/wrappers/LogoutPageWrapper.js +0 -21
- package/src/wrappers/RegisterFormWrapper.d.ts +0 -20
- package/src/wrappers/RegisterFormWrapper.d.ts.map +0 -1
- package/src/wrappers/RegisterFormWrapper.js +0 -51
- package/src/wrappers/ResetPasswordFormWrapper.d.ts +0 -9
- package/src/wrappers/ResetPasswordFormWrapper.d.ts.map +0 -1
- package/src/wrappers/ResetPasswordFormWrapper.js +0 -34
- package/src/wrappers/UserSettingsFormWrapper.d.ts +0 -29
- package/src/wrappers/UserSettingsFormWrapper.d.ts.map +0 -1
- package/src/wrappers/UserSettingsFormWrapper.js +0 -95
- package/src/wrappers/VerifyEmailPageWrapper.d.ts +0 -8
- package/src/wrappers/VerifyEmailPageWrapper.d.ts.map +0 -1
- package/src/wrappers/VerifyEmailPageWrapper.js +0 -21
- package/src/wrappers/index.d.ts.map +0 -1
- package/src/wrappers/index.js +0 -24
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Branded type for menu type identifiers
|
|
2
|
+
export type MenuType = string & { readonly __brand: 'MenuType' };
|
|
3
|
+
|
|
4
|
+
// Factory function to create menu types
|
|
5
|
+
export const createMenuType = (id: string): MenuType => id as MenuType;
|
|
6
|
+
|
|
7
|
+
// Built-in menu types
|
|
8
|
+
export const MenuTypes = {
|
|
9
|
+
SideMenu: createMenuType('SideMenu'),
|
|
10
|
+
TopMenu: createMenuType('TopMenu'),
|
|
11
|
+
UserMenu: createMenuType('UserMenu'),
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
// Type for the built-in menu types
|
|
15
|
+
export type BuiltInMenuType = typeof MenuTypes[keyof typeof MenuTypes];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const ExpirationSecondsOptionValues = [0, 10, 30, 45, 60, 120, 300, 600];
|
|
2
|
+
|
|
3
|
+
export function createExpirationSecondsOptionNames(
|
|
4
|
+
secondsLabel: string,
|
|
5
|
+
minuteLabel: string,
|
|
6
|
+
minutesLabel: string
|
|
7
|
+
): string[] {
|
|
8
|
+
return [
|
|
9
|
+
`0 ${secondsLabel}`,
|
|
10
|
+
`10 ${secondsLabel}`,
|
|
11
|
+
`30 ${secondsLabel}`,
|
|
12
|
+
`45 ${secondsLabel}`,
|
|
13
|
+
`1 ${minuteLabel}`,
|
|
14
|
+
`2 ${minutesLabel}`,
|
|
15
|
+
`5 ${minutesLabel}`,
|
|
16
|
+
`10 ${minutesLabel}`,
|
|
17
|
+
];
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MenuType';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translation function type for components
|
|
3
|
+
* Accepts a key and optional variables, returns translated string
|
|
4
|
+
*/
|
|
5
|
+
export type TranslationFunction = (
|
|
6
|
+
key: string,
|
|
7
|
+
variables?: Record<string, string | number>
|
|
8
|
+
) => string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Helper to get translated text or fallback to provided string
|
|
12
|
+
*/
|
|
13
|
+
export function getTranslatedText(
|
|
14
|
+
t: TranslationFunction | undefined,
|
|
15
|
+
key: string,
|
|
16
|
+
fallback: string,
|
|
17
|
+
variables?: Record<string, string | number>
|
|
18
|
+
): string {
|
|
19
|
+
return t ? t(key, variables) : fallback;
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router';
|
|
3
|
+
import { BackupCodeLoginForm } from '../components/BackupCodeLoginForm';
|
|
4
|
+
import { useAuth } from '../contexts';
|
|
5
|
+
|
|
6
|
+
export interface BackupCodeLoginWrapperProps {
|
|
7
|
+
onSuccess?: () => void;
|
|
8
|
+
componentProps?: Partial<React.ComponentProps<typeof BackupCodeLoginForm>>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const BackupCodeLoginWrapper: FC<BackupCodeLoginWrapperProps> = ({
|
|
12
|
+
onSuccess,
|
|
13
|
+
componentProps = {},
|
|
14
|
+
}) => {
|
|
15
|
+
const { backupCodeLogin, isAuthenticated } = useAuth();
|
|
16
|
+
const navigate = useNavigate();
|
|
17
|
+
|
|
18
|
+
const handleSubmit: typeof backupCodeLogin = async (...args) => {
|
|
19
|
+
const result = await backupCodeLogin(...args);
|
|
20
|
+
if ('token' in result && onSuccess) {
|
|
21
|
+
onSuccess();
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<BackupCodeLoginForm
|
|
28
|
+
onSubmit={handleSubmit}
|
|
29
|
+
onNavigate={navigate}
|
|
30
|
+
isAuthenticated={isAuthenticated}
|
|
31
|
+
{...componentProps}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { useLocation } from 'react-router';
|
|
3
|
+
import { BackupCodesForm } from '../components/BackupCodesForm';
|
|
4
|
+
import { useBackupCodes } from '../hooks';
|
|
5
|
+
|
|
6
|
+
export interface BackupCodesWrapperProps {
|
|
7
|
+
componentProps?: Partial<React.ComponentProps<typeof BackupCodesForm>>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const BackupCodesWrapper: FC<BackupCodesWrapperProps> = ({
|
|
11
|
+
componentProps = {},
|
|
12
|
+
}) => {
|
|
13
|
+
const location = useLocation();
|
|
14
|
+
const initialCodeCount = (location.state as { codeCount?: number })?.codeCount ?? null;
|
|
15
|
+
const { backupCodesRemaining, generateBackupCodes } = useBackupCodes({ initialCodeCount });
|
|
16
|
+
|
|
17
|
+
const handleSubmit = async (values: { password?: string; mnemonic?: string }) => {
|
|
18
|
+
return await generateBackupCodes(values.password, values.mnemonic);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<BackupCodesForm
|
|
23
|
+
onSubmit={handleSubmit}
|
|
24
|
+
backupCodesRemaining={backupCodesRemaining}
|
|
25
|
+
{...componentProps}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ChangePasswordForm } from '../components/ChangePasswordForm';
|
|
3
|
+
import { useAuth } from '../contexts';
|
|
4
|
+
|
|
5
|
+
export interface ChangePasswordFormWrapperProps {
|
|
6
|
+
onSuccess?: () => void;
|
|
7
|
+
componentProps?: Partial<React.ComponentProps<typeof ChangePasswordForm>>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const ChangePasswordFormWrapper: FC<ChangePasswordFormWrapperProps> = ({
|
|
11
|
+
onSuccess,
|
|
12
|
+
componentProps = {},
|
|
13
|
+
}) => {
|
|
14
|
+
const { changePassword } = useAuth();
|
|
15
|
+
|
|
16
|
+
const handleSubmit = async (values: {
|
|
17
|
+
currentPassword: string;
|
|
18
|
+
newPassword: string;
|
|
19
|
+
}) => {
|
|
20
|
+
const result = await changePassword(
|
|
21
|
+
values.currentPassword,
|
|
22
|
+
values.newPassword
|
|
23
|
+
);
|
|
24
|
+
if ('error' in result) {
|
|
25
|
+
return { error: result.error };
|
|
26
|
+
}
|
|
27
|
+
if (onSuccess) {
|
|
28
|
+
onSuccess();
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return <ChangePasswordForm onSubmit={handleSubmit} {...componentProps} />;
|
|
34
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
SuiteCoreStringKey,
|
|
4
|
+
TranslatableSuiteError,
|
|
5
|
+
} from '@digitaldefiance/suite-core-lib';
|
|
6
|
+
import {
|
|
7
|
+
ForgotPasswordForm,
|
|
8
|
+
ForgotPasswordFormProps,
|
|
9
|
+
ForgotPasswordFormValues,
|
|
10
|
+
} from '../components/ForgotPasswordForm';
|
|
11
|
+
import { useSuiteConfig } from '../contexts';
|
|
12
|
+
|
|
13
|
+
export interface ForgotPasswordFormWrapperProps {
|
|
14
|
+
onSuccess?: () => void;
|
|
15
|
+
componentProps?: Partial<Omit<ForgotPasswordFormProps, 'onSubmit'>>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ForgotPasswordFormWrapper: FC<ForgotPasswordFormWrapperProps> = ({
|
|
19
|
+
onSuccess,
|
|
20
|
+
componentProps = {},
|
|
21
|
+
}) => {
|
|
22
|
+
const { baseUrl } = useSuiteConfig();
|
|
23
|
+
|
|
24
|
+
const handleSubmit = async (values: ForgotPasswordFormValues) => {
|
|
25
|
+
const res = await fetch(`${baseUrl}/user/forgot-password`, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: { 'Content-Type': 'application/json' },
|
|
28
|
+
body: JSON.stringify({ email: values.email }),
|
|
29
|
+
});
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
const body: { message?: string } = await res.json().catch(() => ({})) as { message?: string };
|
|
32
|
+
if (body.message) {
|
|
33
|
+
throw new Error(body.message);
|
|
34
|
+
}
|
|
35
|
+
throw new TranslatableSuiteError(
|
|
36
|
+
SuiteCoreStringKey.ForgotPassword_Error,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (onSuccess) {
|
|
40
|
+
onSuccess();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return <ForgotPasswordForm onSubmit={handleSubmit} {...componentProps} />;
|
|
45
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { FC, useState } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router';
|
|
3
|
+
import { SecureString, EmailString } from '@digitaldefiance/ecies-lib';
|
|
4
|
+
import { IRequestUserDTO, SuiteCoreStringKey, TranslatableSuiteError } from '@digitaldefiance/suite-core-lib';
|
|
5
|
+
import { LoginForm, LoginFormValues, LoginFormProps } from '../components/LoginForm';
|
|
6
|
+
import { TotpVerificationForm } from '../components/TotpVerificationForm';
|
|
7
|
+
import { useAuth, useSuiteConfig } from '../contexts';
|
|
8
|
+
|
|
9
|
+
export interface LoginFormWrapperProps {
|
|
10
|
+
onSuccess?: () => void;
|
|
11
|
+
redirectTo?: string;
|
|
12
|
+
componentProps?: Partial<Omit<LoginFormProps, 'onSubmit'>>;
|
|
13
|
+
/**
|
|
14
|
+
* Called when the user submits a TOTP verification code during login.
|
|
15
|
+
* Typically wired to `AuthService.verifyTotpLogin(pendingTotpToken, code)`.
|
|
16
|
+
* When not provided, the wrapper cannot complete TOTP-protected logins.
|
|
17
|
+
*/
|
|
18
|
+
onVerifyTotp?: (
|
|
19
|
+
code: string,
|
|
20
|
+
pendingTotpToken: string,
|
|
21
|
+
) => Promise<{ token: string; user: IRequestUserDTO } | { error: string }>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const LoginFormWrapper: FC<LoginFormWrapperProps> = ({
|
|
25
|
+
onSuccess,
|
|
26
|
+
redirectTo,
|
|
27
|
+
componentProps = {},
|
|
28
|
+
onVerifyTotp,
|
|
29
|
+
}) => {
|
|
30
|
+
const { directLogin, passwordLogin, verifyTotpLogin, setUser } = useAuth();
|
|
31
|
+
const navigate = useNavigate();
|
|
32
|
+
const { routes } = useSuiteConfig();
|
|
33
|
+
const [pendingTotpToken, setPendingTotpToken] = useState<string | null>(null);
|
|
34
|
+
|
|
35
|
+
const handleLoginSuccess = () => {
|
|
36
|
+
if (onSuccess) {
|
|
37
|
+
onSuccess();
|
|
38
|
+
}
|
|
39
|
+
navigate(redirectTo || routes.dashboard || '/dashboard');
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const handleSubmit = async (values: LoginFormValues) => {
|
|
43
|
+
const email = values.email && values.email.trim().length > 0 ? new EmailString(values.email) : undefined;
|
|
44
|
+
const username = values.username && values.username.trim() ? values.username : undefined;
|
|
45
|
+
|
|
46
|
+
if (values.password) {
|
|
47
|
+
const result = await passwordLogin(
|
|
48
|
+
new SecureString(values.password),
|
|
49
|
+
username,
|
|
50
|
+
email
|
|
51
|
+
);
|
|
52
|
+
if ('error' in result) {
|
|
53
|
+
throw new Error(result.error);
|
|
54
|
+
}
|
|
55
|
+
if ('pendingTotpToken' in result) {
|
|
56
|
+
setPendingTotpToken(result.pendingTotpToken);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
handleLoginSuccess();
|
|
60
|
+
} else if (values.mnemonic) {
|
|
61
|
+
const result = await directLogin(
|
|
62
|
+
new SecureString(values.mnemonic),
|
|
63
|
+
username,
|
|
64
|
+
email
|
|
65
|
+
);
|
|
66
|
+
if ('error' in result) {
|
|
67
|
+
throw new Error(result.error);
|
|
68
|
+
}
|
|
69
|
+
if ('pendingTotpToken' in result) {
|
|
70
|
+
setPendingTotpToken(result.pendingTotpToken);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
handleLoginSuccess();
|
|
74
|
+
} else {
|
|
75
|
+
throw new TranslatableSuiteError(SuiteCoreStringKey.Error_NoPasswordOrMnemonicProvided);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const handleTotpSubmit = async (
|
|
80
|
+
code: string,
|
|
81
|
+
token: string,
|
|
82
|
+
): Promise<{ token: string; user: IRequestUserDTO } | { error: string }> => {
|
|
83
|
+
// Use the explicitly provided callback, or fall back to verifyTotpLogin from AuthContext
|
|
84
|
+
const verifyFn = onVerifyTotp ?? ((c: string, t: string) => verifyTotpLogin(t, c));
|
|
85
|
+
const result = await verifyFn(code, token);
|
|
86
|
+
if ('error' in result) {
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
// Store the full JWT and complete the login flow
|
|
90
|
+
localStorage.setItem('authToken', result.token);
|
|
91
|
+
localStorage.setItem('user', JSON.stringify(result.user));
|
|
92
|
+
// Update auth context so PrivateRoute guards see the user as authenticated
|
|
93
|
+
await setUser(result.user);
|
|
94
|
+
handleLoginSuccess();
|
|
95
|
+
return result;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (pendingTotpToken) {
|
|
99
|
+
return (
|
|
100
|
+
<TotpVerificationForm
|
|
101
|
+
pendingTotpToken={pendingTotpToken}
|
|
102
|
+
onSubmit={handleTotpSubmit}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return <LoginForm onSubmit={handleSubmit} {...componentProps} />;
|
|
108
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router';
|
|
3
|
+
import { LogoutPage } from '../components/LogoutPage';
|
|
4
|
+
import { useAuth, useSuiteConfig } from '../contexts';
|
|
5
|
+
|
|
6
|
+
export interface LogoutPageWrapperProps {
|
|
7
|
+
onSuccess?: () => void;
|
|
8
|
+
redirectTo?: string;
|
|
9
|
+
componentProps?: Partial<React.ComponentProps<typeof LogoutPage>>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const LogoutPageWrapper: FC<LogoutPageWrapperProps> = ({
|
|
13
|
+
onSuccess,
|
|
14
|
+
redirectTo,
|
|
15
|
+
componentProps = {},
|
|
16
|
+
}) => {
|
|
17
|
+
const { logout } = useAuth();
|
|
18
|
+
const navigate = useNavigate();
|
|
19
|
+
const { routes } = useSuiteConfig();
|
|
20
|
+
|
|
21
|
+
const handleLogout = async () => {
|
|
22
|
+
await logout();
|
|
23
|
+
if (onSuccess) {
|
|
24
|
+
onSuccess();
|
|
25
|
+
}
|
|
26
|
+
navigate(redirectTo || routes.login || '/login');
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return <LogoutPage onLogout={handleLogout} onNavigate={navigate} {...componentProps} />;
|
|
30
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { SecureString } from '@digitaldefiance/ecies-lib';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
RegisterForm,
|
|
5
|
+
RegisterFormProps,
|
|
6
|
+
RegisterFormValues,
|
|
7
|
+
} from '../components/RegisterForm';
|
|
8
|
+
import { useAuth, useSuiteConfig } from '../contexts';
|
|
9
|
+
|
|
10
|
+
export interface RegisterFormWrapperProps {
|
|
11
|
+
onSuccess?: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* When true, offer the TOTP setup step after successful registration.
|
|
14
|
+
* Typically sourced from window.APP_CONFIG.totpAvailable.
|
|
15
|
+
* Defaults to false.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: This requires the registration endpoint to return a session token
|
|
18
|
+
* so the user is authenticated when the TOTP setup call is made. If
|
|
19
|
+
* registration does not issue a token (the default in this suite), leave
|
|
20
|
+
* this false and direct users to enable TOTP from their settings page
|
|
21
|
+
* after logging in.
|
|
22
|
+
*/
|
|
23
|
+
enableTotpSetup?: boolean;
|
|
24
|
+
componentProps?: Partial<
|
|
25
|
+
Omit<RegisterFormProps, 'onSubmit' | 'timezones' | 'getInitialTimezone'>
|
|
26
|
+
>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const RegisterFormWrapper: FC<RegisterFormWrapperProps> = ({
|
|
30
|
+
onSuccess,
|
|
31
|
+
enableTotpSetup = false,
|
|
32
|
+
componentProps = {},
|
|
33
|
+
}) => {
|
|
34
|
+
const { register, setUpBrowserPasswordLogin, setupTotp, confirmTotp } =
|
|
35
|
+
useAuth();
|
|
36
|
+
const { timezones } = useSuiteConfig();
|
|
37
|
+
|
|
38
|
+
const handleSubmit = async (
|
|
39
|
+
values: RegisterFormValues,
|
|
40
|
+
usePassword: boolean
|
|
41
|
+
) => {
|
|
42
|
+
const result = await register(
|
|
43
|
+
values.username,
|
|
44
|
+
values.email,
|
|
45
|
+
values.timezone || 'UTC',
|
|
46
|
+
values.password,
|
|
47
|
+
values.mnemonic,
|
|
48
|
+
values.displayName,
|
|
49
|
+
values.directChallenge
|
|
50
|
+
);
|
|
51
|
+
if ('error' in result) {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// After successful registration with a password, set up the browser-side
|
|
56
|
+
// password login bundle (encrypts mnemonic with password and stores in localStorage).
|
|
57
|
+
// This is required for subsequent password-based logins to work.
|
|
58
|
+
if (usePassword && values.password && result.mnemonic) {
|
|
59
|
+
const setupResult = await setUpBrowserPasswordLogin(
|
|
60
|
+
new SecureString(result.mnemonic),
|
|
61
|
+
new SecureString(values.password)
|
|
62
|
+
);
|
|
63
|
+
if ('error' in setupResult) {
|
|
64
|
+
// Password login setup failed — still return success for registration
|
|
65
|
+
// but log the issue. The user can set up password login later.
|
|
66
|
+
console.warn(
|
|
67
|
+
'Registration succeeded but browser password login setup failed:',
|
|
68
|
+
setupResult.error
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (onSuccess) {
|
|
74
|
+
onSuccess();
|
|
75
|
+
}
|
|
76
|
+
// Don't navigate away — let RegisterForm show the success message
|
|
77
|
+
// (mnemonic grid or email verification notice). The user navigates
|
|
78
|
+
// manually via the "Proceed to login" / "I Have Saved My Recovery
|
|
79
|
+
// Phrase" button.
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const defaultTimezones = timezones || [
|
|
84
|
+
'UTC',
|
|
85
|
+
'America/New_York',
|
|
86
|
+
'America/Los_Angeles',
|
|
87
|
+
'Europe/London',
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
const totpProps = enableTotpSetup
|
|
91
|
+
? {
|
|
92
|
+
enableTotpSetup: true,
|
|
93
|
+
onTotpSetup: setupTotp,
|
|
94
|
+
onTotpConfirm: confirmTotp,
|
|
95
|
+
}
|
|
96
|
+
: {};
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<RegisterForm
|
|
100
|
+
onSubmit={handleSubmit}
|
|
101
|
+
timezones={defaultTimezones}
|
|
102
|
+
getInitialTimezone={() =>
|
|
103
|
+
Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC'
|
|
104
|
+
}
|
|
105
|
+
{...totpProps}
|
|
106
|
+
{...componentProps}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { useNavigate, useSearchParams } from 'react-router';
|
|
3
|
+
import {
|
|
4
|
+
SuiteCoreStringKey,
|
|
5
|
+
TranslatableSuiteError,
|
|
6
|
+
} from '@digitaldefiance/suite-core-lib';
|
|
7
|
+
import {
|
|
8
|
+
ResetPasswordForm,
|
|
9
|
+
ResetPasswordFormProps,
|
|
10
|
+
} from '../components/ResetPasswordForm';
|
|
11
|
+
import { useSuiteConfig } from '../contexts';
|
|
12
|
+
|
|
13
|
+
export interface ResetPasswordFormWrapperProps {
|
|
14
|
+
onSuccess?: () => void;
|
|
15
|
+
redirectTo?: string;
|
|
16
|
+
componentProps?: Partial<Omit<ResetPasswordFormProps, 'onSubmit' | 'token'>>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ResetPasswordFormWrapper: FC<ResetPasswordFormWrapperProps> = ({
|
|
20
|
+
onSuccess,
|
|
21
|
+
redirectTo,
|
|
22
|
+
componentProps = {},
|
|
23
|
+
}) => {
|
|
24
|
+
const { baseUrl, routes } = useSuiteConfig();
|
|
25
|
+
const navigate = useNavigate();
|
|
26
|
+
const [searchParams] = useSearchParams();
|
|
27
|
+
const token = searchParams.get('token');
|
|
28
|
+
|
|
29
|
+
const handleSubmit = async (resetToken: string, password: string) => {
|
|
30
|
+
const res = await fetch(`${baseUrl}/user/reset-password`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: { 'Content-Type': 'application/json' },
|
|
33
|
+
body: JSON.stringify({ token: resetToken, password }),
|
|
34
|
+
});
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
const body: { message?: string } = await res.json().catch(() => ({})) as { message?: string };
|
|
37
|
+
if (body.message) {
|
|
38
|
+
throw new Error(body.message);
|
|
39
|
+
}
|
|
40
|
+
throw new TranslatableSuiteError(
|
|
41
|
+
SuiteCoreStringKey.Error_PasswordChange,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (onSuccess) {
|
|
45
|
+
onSuccess();
|
|
46
|
+
}
|
|
47
|
+
navigate(redirectTo || routes.login || '/login');
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<ResetPasswordForm
|
|
52
|
+
token={token}
|
|
53
|
+
onSubmit={handleSubmit}
|
|
54
|
+
{...componentProps}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { UserSettingsForm, UserSettingsFormValues, UserSettingsFormProps } from '../components/UserSettingsForm';
|
|
3
|
+
import { useSuiteConfig } from '../contexts';
|
|
4
|
+
import { useUserSettingsPublic } from '../hooks';
|
|
5
|
+
import { getSuiteCoreTranslation, IConstants, SuiteCoreStringKey } from '@digitaldefiance/suite-core-lib';
|
|
6
|
+
import { createAuthService } from '../services/authService';
|
|
7
|
+
import { createAuthenticatedApiClient } from '../services/authenticatedApi';
|
|
8
|
+
import { IECIESConfig } from '@digitaldefiance/ecies-lib';
|
|
9
|
+
|
|
10
|
+
export interface UserSettingsFormWrapperProps {
|
|
11
|
+
onSuccess?: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Constants for AuthService (required for TOTP methods).
|
|
14
|
+
* If not provided, TOTP callbacks will not be wired up.
|
|
15
|
+
*/
|
|
16
|
+
constants?: IConstants;
|
|
17
|
+
/**
|
|
18
|
+
* ECIES config for AuthService (required for TOTP methods).
|
|
19
|
+
* If not provided, TOTP callbacks will not be wired up.
|
|
20
|
+
*/
|
|
21
|
+
eciesConfig?: IECIESConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Email domain for AuthService (required for TOTP methods).
|
|
24
|
+
*/
|
|
25
|
+
emailDomain?: string;
|
|
26
|
+
/**
|
|
27
|
+
* When false (default), TOTP management controls are not shown.
|
|
28
|
+
* Set to true when TOTP_AVAILABLE is enabled in the server environment.
|
|
29
|
+
*/
|
|
30
|
+
totpAvailable?: boolean;
|
|
31
|
+
componentProps?: Partial<Omit<UserSettingsFormProps, 'initialValues' | 'onSubmit' | 'languages'>>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const UserSettingsFormWrapper: FC<UserSettingsFormWrapperProps> = ({
|
|
35
|
+
onSuccess,
|
|
36
|
+
constants,
|
|
37
|
+
eciesConfig,
|
|
38
|
+
emailDomain = '',
|
|
39
|
+
totpAvailable = false,
|
|
40
|
+
componentProps = {},
|
|
41
|
+
}) => {
|
|
42
|
+
const { settings, updateSettings } = useUserSettingsPublic();
|
|
43
|
+
const { languages, baseUrl } = useSuiteConfig();
|
|
44
|
+
|
|
45
|
+
// Fetch totpEnabled from the settings API
|
|
46
|
+
const [totpEnabled, setTotpEnabled] = useState<boolean | undefined>(undefined);
|
|
47
|
+
|
|
48
|
+
const authenticatedApi = useMemo(
|
|
49
|
+
() => createAuthenticatedApiClient(baseUrl),
|
|
50
|
+
[baseUrl],
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const authService = useMemo(() => {
|
|
54
|
+
if (!constants || !eciesConfig) return null;
|
|
55
|
+
return createAuthService(constants, baseUrl, eciesConfig, emailDomain);
|
|
56
|
+
}, [constants, eciesConfig, baseUrl, emailDomain]);
|
|
57
|
+
|
|
58
|
+
// Fetch totpEnabled from GET /user/settings.
|
|
59
|
+
// We gate on totpAvailable (no point fetching if TOTP isn't enabled on this
|
|
60
|
+
// deployment) but NOT on isAuthenticated — isAuthenticated can be false
|
|
61
|
+
// transiently (e.g. verify 403 on page refresh with a stale token) even
|
|
62
|
+
// when the user has a valid session token in localStorage. The
|
|
63
|
+
// authenticatedApi interceptor attaches the token automatically; if the
|
|
64
|
+
// call fails we leave totpEnabled undefined so no TOTP controls are shown.
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!totpAvailable) return;
|
|
67
|
+
authenticatedApi
|
|
68
|
+
.get<{ settings: { totpEnabled?: boolean } }>('/user/settings')
|
|
69
|
+
.then((res) => {
|
|
70
|
+
setTotpEnabled(res.data?.settings?.totpEnabled ?? false);
|
|
71
|
+
})
|
|
72
|
+
.catch(() => {
|
|
73
|
+
// If the endpoint fails, leave totpEnabled undefined (no TOTP controls shown)
|
|
74
|
+
});
|
|
75
|
+
}, [totpAvailable, authenticatedApi]);
|
|
76
|
+
|
|
77
|
+
const handleSubmit = async (values: UserSettingsFormValues) => {
|
|
78
|
+
const result = await updateSettings(values);
|
|
79
|
+
if ('success' in result && result.success && onSuccess) {
|
|
80
|
+
onSuccess();
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// TOTP callbacks — only wired when authService is available
|
|
86
|
+
const handleTotpSetup = useCallback(async () => {
|
|
87
|
+
if (!authService) return { error: 'AuthService not configured' };
|
|
88
|
+
return authService.setupTotp();
|
|
89
|
+
}, [authService]);
|
|
90
|
+
|
|
91
|
+
const handleTotpConfirm = useCallback(async (code: string) => {
|
|
92
|
+
if (!authService) return { error: 'AuthService not configured' };
|
|
93
|
+
const result = await authService.confirmTotp(code);
|
|
94
|
+
if ('success' in result && result.success) {
|
|
95
|
+
setTotpEnabled(true);
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}, [authService]);
|
|
99
|
+
|
|
100
|
+
const handleTotpDisable = useCallback(async (code: string) => {
|
|
101
|
+
if (!authService) return { error: 'AuthService not configured' };
|
|
102
|
+
const result = await authService.disableTotp(code);
|
|
103
|
+
if ('success' in result && result.success) {
|
|
104
|
+
setTotpEnabled(false);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}, [authService]);
|
|
108
|
+
|
|
109
|
+
const handleTotpReset = useCallback(async (code: string) => {
|
|
110
|
+
if (!authService) return { error: 'AuthService not configured' };
|
|
111
|
+
return authService.resetTotp(code);
|
|
112
|
+
}, [authService]);
|
|
113
|
+
|
|
114
|
+
// Only show loading on initial load, not during updates
|
|
115
|
+
// Once we have settings, keep showing the form even during updates
|
|
116
|
+
if (!settings) {
|
|
117
|
+
return <div>{getSuiteCoreTranslation(SuiteCoreStringKey.Common_Loading)}...</div>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Only pass TOTP props when totpAvailable is true, authService is available, and totpEnabled has been fetched
|
|
121
|
+
const totpProps = totpAvailable && authService && totpEnabled !== undefined
|
|
122
|
+
? {
|
|
123
|
+
totpEnabled,
|
|
124
|
+
onTotpSetup: handleTotpSetup,
|
|
125
|
+
onTotpConfirm: handleTotpConfirm,
|
|
126
|
+
onTotpDisable: handleTotpDisable,
|
|
127
|
+
onTotpReset: handleTotpReset,
|
|
128
|
+
}
|
|
129
|
+
: {};
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<UserSettingsForm
|
|
133
|
+
initialValues={settings}
|
|
134
|
+
onSubmit={handleSubmit}
|
|
135
|
+
languages={languages}
|
|
136
|
+
{...totpProps}
|
|
137
|
+
{...componentProps}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FC, useCallback } from 'react';
|
|
2
|
+
import { VerifyEmailPage } from '../components/VerifyEmailPage';
|
|
3
|
+
import { useEmailVerification } from '../hooks';
|
|
4
|
+
|
|
5
|
+
export interface VerifyEmailPageWrapperProps {
|
|
6
|
+
onSuccess?: () => void;
|
|
7
|
+
componentProps?: Partial<React.ComponentProps<typeof VerifyEmailPage>>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const VerifyEmailPageWrapper: FC<VerifyEmailPageWrapperProps> = ({
|
|
11
|
+
onSuccess,
|
|
12
|
+
componentProps = {},
|
|
13
|
+
}) => {
|
|
14
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
15
|
+
const token = searchParams.get('token');
|
|
16
|
+
const { verifyEmail } = useEmailVerification();
|
|
17
|
+
|
|
18
|
+
const handleVerify = useCallback(async (verificationToken: string) => {
|
|
19
|
+
const result = await verifyEmail(verificationToken);
|
|
20
|
+
if (result.success && onSuccess) {
|
|
21
|
+
onSuccess();
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}, [verifyEmail, onSuccess]);
|
|
25
|
+
|
|
26
|
+
return <VerifyEmailPage token={token} onVerify={handleVerify} {...componentProps} />;
|
|
27
|
+
};
|