@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,339 @@
|
|
|
1
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
2
|
+
import { LoginFormWrapper, LoginFormWrapperProps } from '../LoginFormWrapper';
|
|
3
|
+
|
|
4
|
+
// --- Mocks ---
|
|
5
|
+
|
|
6
|
+
const mockNavigate = jest.fn();
|
|
7
|
+
jest.mock('react-router', () => ({
|
|
8
|
+
useNavigate: () => mockNavigate,
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
const mockDirectLogin = jest.fn();
|
|
12
|
+
const mockPasswordLogin = jest.fn();
|
|
13
|
+
const mockSetUser = jest.fn();
|
|
14
|
+
const mockVerifyTotpLogin = jest.fn();
|
|
15
|
+
jest.mock('../../contexts', () => ({
|
|
16
|
+
useAuth: () => ({
|
|
17
|
+
directLogin: mockDirectLogin,
|
|
18
|
+
passwordLogin: mockPasswordLogin,
|
|
19
|
+
setUser: mockSetUser,
|
|
20
|
+
verifyTotpLogin: mockVerifyTotpLogin,
|
|
21
|
+
}),
|
|
22
|
+
useSuiteConfig: () => ({
|
|
23
|
+
routes: {
|
|
24
|
+
dashboard: '/dashboard',
|
|
25
|
+
login: '/login',
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
// Minimal LoginForm mock that exposes the onSubmit prop
|
|
31
|
+
jest.mock('../../components/LoginForm', () => ({
|
|
32
|
+
LoginForm: (props: {
|
|
33
|
+
onSubmit: (values: Record<string, string>) => Promise<void>;
|
|
34
|
+
}) => (
|
|
35
|
+
<div data-testid="login-form">
|
|
36
|
+
<button
|
|
37
|
+
data-testid="login-password-btn"
|
|
38
|
+
onClick={() =>
|
|
39
|
+
props.onSubmit({ email: 'user@example.com', password: 'secret' })
|
|
40
|
+
}
|
|
41
|
+
>
|
|
42
|
+
Login with password
|
|
43
|
+
</button>
|
|
44
|
+
<button
|
|
45
|
+
data-testid="login-mnemonic-btn"
|
|
46
|
+
onClick={() =>
|
|
47
|
+
props.onSubmit({
|
|
48
|
+
username: 'testuser',
|
|
49
|
+
mnemonic: 'word1 word2 word3',
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
>
|
|
53
|
+
Login with mnemonic
|
|
54
|
+
</button>
|
|
55
|
+
</div>
|
|
56
|
+
),
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
// Minimal TotpVerificationForm mock that exposes onSubmit
|
|
60
|
+
jest.mock('../../components/TotpVerificationForm', () => ({
|
|
61
|
+
TotpVerificationForm: (props: {
|
|
62
|
+
pendingTotpToken: string;
|
|
63
|
+
onSubmit: (
|
|
64
|
+
code: string,
|
|
65
|
+
token: string
|
|
66
|
+
) => Promise<{ token: string; user: object } | { error: string }>;
|
|
67
|
+
}) => (
|
|
68
|
+
<div data-testid="totp-verification-form">
|
|
69
|
+
<span data-testid="pending-token">{props.pendingTotpToken}</span>
|
|
70
|
+
<button
|
|
71
|
+
data-testid="totp-submit-btn"
|
|
72
|
+
onClick={() => props.onSubmit('123456', props.pendingTotpToken)}
|
|
73
|
+
>
|
|
74
|
+
Verify TOTP
|
|
75
|
+
</button>
|
|
76
|
+
</div>
|
|
77
|
+
),
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
describe('LoginFormWrapper TOTP integration', () => {
|
|
81
|
+
const originalError = console.error;
|
|
82
|
+
beforeAll(() => {
|
|
83
|
+
console.error = (...args: unknown[]) => {
|
|
84
|
+
if (
|
|
85
|
+
typeof args[0] === 'string' &&
|
|
86
|
+
args[0].includes('not wrapped in act')
|
|
87
|
+
) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
originalError.call(console, ...args);
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
afterAll(() => {
|
|
95
|
+
console.error = originalError;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
jest.clearAllMocks();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const defaultProps: LoginFormWrapperProps = {
|
|
103
|
+
onVerifyTotp: jest.fn(),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Validates: Requirement 14.4
|
|
108
|
+
* Existing login flow is unchanged when no pendingTotpToken is returned.
|
|
109
|
+
*/
|
|
110
|
+
it('renders LoginForm and navigates to dashboard on normal login (no TOTP)', async () => {
|
|
111
|
+
mockPasswordLogin.mockResolvedValue({
|
|
112
|
+
token: 'full-jwt',
|
|
113
|
+
user: { id: '1', email: 'user@example.com' },
|
|
114
|
+
wallet: {},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
render(<LoginFormWrapper {...defaultProps} />);
|
|
118
|
+
|
|
119
|
+
// LoginForm should be rendered
|
|
120
|
+
expect(screen.getByTestId('login-form')).toBeInTheDocument();
|
|
121
|
+
expect(
|
|
122
|
+
screen.queryByTestId('totp-verification-form')
|
|
123
|
+
).not.toBeInTheDocument();
|
|
124
|
+
|
|
125
|
+
// Trigger a password login
|
|
126
|
+
fireEvent.click(screen.getByTestId('login-password-btn'));
|
|
127
|
+
|
|
128
|
+
await waitFor(() => {
|
|
129
|
+
expect(mockPasswordLogin).toHaveBeenCalled();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await waitFor(() => {
|
|
133
|
+
expect(mockNavigate).toHaveBeenCalledWith('/dashboard');
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Validates: Requirement 6.6
|
|
139
|
+
* When passwordLogin returns pendingTotpToken, TotpVerificationForm is rendered.
|
|
140
|
+
*/
|
|
141
|
+
it('renders TotpVerificationForm when passwordLogin returns pendingTotpToken', async () => {
|
|
142
|
+
mockPasswordLogin.mockResolvedValue({
|
|
143
|
+
pendingTotpToken: 'pending-jwt-token',
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
render(<LoginFormWrapper {...defaultProps} />);
|
|
147
|
+
|
|
148
|
+
// Trigger a password login that returns a pending TOTP token
|
|
149
|
+
fireEvent.click(screen.getByTestId('login-password-btn'));
|
|
150
|
+
|
|
151
|
+
await waitFor(() => {
|
|
152
|
+
expect(screen.getByTestId('totp-verification-form')).toBeInTheDocument();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// LoginForm should no longer be visible
|
|
156
|
+
expect(screen.queryByTestId('login-form')).not.toBeInTheDocument();
|
|
157
|
+
|
|
158
|
+
// The pending token should be passed to the form
|
|
159
|
+
expect(screen.getByTestId('pending-token')).toHaveTextContent(
|
|
160
|
+
'pending-jwt-token'
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Validates: Requirement 6.6
|
|
166
|
+
* When directLogin returns pendingTotpToken, TotpVerificationForm is rendered.
|
|
167
|
+
*/
|
|
168
|
+
it('renders TotpVerificationForm when directLogin returns pendingTotpToken', async () => {
|
|
169
|
+
mockDirectLogin.mockResolvedValue({
|
|
170
|
+
pendingTotpToken: 'pending-mnemonic-token',
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
render(<LoginFormWrapper {...defaultProps} />);
|
|
174
|
+
|
|
175
|
+
// Trigger a mnemonic login that returns a pending TOTP token
|
|
176
|
+
fireEvent.click(screen.getByTestId('login-mnemonic-btn'));
|
|
177
|
+
|
|
178
|
+
await waitFor(() => {
|
|
179
|
+
expect(screen.getByTestId('totp-verification-form')).toBeInTheDocument();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
expect(screen.getByTestId('pending-token')).toHaveTextContent(
|
|
183
|
+
'pending-mnemonic-token'
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Validates: Requirement 6.3
|
|
189
|
+
* On successful TOTP verification, navigates to dashboard.
|
|
190
|
+
*/
|
|
191
|
+
it('navigates to dashboard on successful TOTP verification', async () => {
|
|
192
|
+
mockPasswordLogin.mockResolvedValue({
|
|
193
|
+
pendingTotpToken: 'pending-jwt-token',
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const mockVerifyTotp = jest.fn().mockResolvedValue({
|
|
197
|
+
token: 'full-jwt-after-totp',
|
|
198
|
+
user: { id: '1', email: 'user@example.com' },
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
render(
|
|
202
|
+
<LoginFormWrapper {...defaultProps} onVerifyTotp={mockVerifyTotp} />
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
// First, trigger login to get pending token
|
|
206
|
+
fireEvent.click(screen.getByTestId('login-password-btn'));
|
|
207
|
+
|
|
208
|
+
await waitFor(() => {
|
|
209
|
+
expect(screen.getByTestId('totp-verification-form')).toBeInTheDocument();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Now submit the TOTP code
|
|
213
|
+
fireEvent.click(screen.getByTestId('totp-submit-btn'));
|
|
214
|
+
|
|
215
|
+
await waitFor(() => {
|
|
216
|
+
expect(mockVerifyTotp).toHaveBeenCalledWith(
|
|
217
|
+
'123456',
|
|
218
|
+
'pending-jwt-token'
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
await waitFor(() => {
|
|
223
|
+
expect(mockNavigate).toHaveBeenCalledWith('/dashboard');
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Validates: Requirement 14.4
|
|
229
|
+
* Navigates to custom redirectTo path after successful login without TOTP.
|
|
230
|
+
*/
|
|
231
|
+
it('navigates to custom redirectTo on normal login', async () => {
|
|
232
|
+
mockPasswordLogin.mockResolvedValue({
|
|
233
|
+
token: 'full-jwt',
|
|
234
|
+
user: { id: '1' },
|
|
235
|
+
wallet: {},
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
render(<LoginFormWrapper {...defaultProps} redirectTo="/custom-page" />);
|
|
239
|
+
|
|
240
|
+
fireEvent.click(screen.getByTestId('login-password-btn'));
|
|
241
|
+
|
|
242
|
+
await waitFor(() => {
|
|
243
|
+
expect(mockNavigate).toHaveBeenCalledWith('/custom-page');
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Validates: Requirement 6.3
|
|
249
|
+
* Navigates to custom redirectTo after successful TOTP verification.
|
|
250
|
+
*/
|
|
251
|
+
it('navigates to custom redirectTo after successful TOTP verification', async () => {
|
|
252
|
+
mockPasswordLogin.mockResolvedValue({
|
|
253
|
+
pendingTotpToken: 'pending-jwt-token',
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const mockVerifyTotp = jest.fn().mockResolvedValue({
|
|
257
|
+
token: 'full-jwt-after-totp',
|
|
258
|
+
user: { id: '1' },
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
render(
|
|
262
|
+
<LoginFormWrapper
|
|
263
|
+
{...defaultProps}
|
|
264
|
+
onVerifyTotp={mockVerifyTotp}
|
|
265
|
+
redirectTo="/custom-page"
|
|
266
|
+
/>
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
fireEvent.click(screen.getByTestId('login-password-btn'));
|
|
270
|
+
|
|
271
|
+
await waitFor(() => {
|
|
272
|
+
expect(screen.getByTestId('totp-verification-form')).toBeInTheDocument();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
fireEvent.click(screen.getByTestId('totp-submit-btn'));
|
|
276
|
+
|
|
277
|
+
await waitFor(() => {
|
|
278
|
+
expect(mockNavigate).toHaveBeenCalledWith('/custom-page');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Validates: Requirement 14.4
|
|
284
|
+
* Calls onSuccess callback on normal login.
|
|
285
|
+
*/
|
|
286
|
+
it('calls onSuccess callback on normal login', async () => {
|
|
287
|
+
mockPasswordLogin.mockResolvedValue({
|
|
288
|
+
token: 'full-jwt',
|
|
289
|
+
user: { id: '1' },
|
|
290
|
+
wallet: {},
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const mockOnSuccess = jest.fn();
|
|
294
|
+
|
|
295
|
+
render(<LoginFormWrapper {...defaultProps} onSuccess={mockOnSuccess} />);
|
|
296
|
+
|
|
297
|
+
fireEvent.click(screen.getByTestId('login-password-btn'));
|
|
298
|
+
|
|
299
|
+
await waitFor(() => {
|
|
300
|
+
expect(mockOnSuccess).toHaveBeenCalled();
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Validates: Requirement 6.3
|
|
306
|
+
* Calls onSuccess callback after successful TOTP verification.
|
|
307
|
+
*/
|
|
308
|
+
it('calls onSuccess callback after successful TOTP verification', async () => {
|
|
309
|
+
mockPasswordLogin.mockResolvedValue({
|
|
310
|
+
pendingTotpToken: 'pending-jwt-token',
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const mockVerifyTotp = jest.fn().mockResolvedValue({
|
|
314
|
+
token: 'full-jwt-after-totp',
|
|
315
|
+
user: { id: '1' },
|
|
316
|
+
});
|
|
317
|
+
const mockOnSuccess = jest.fn();
|
|
318
|
+
|
|
319
|
+
render(
|
|
320
|
+
<LoginFormWrapper
|
|
321
|
+
{...defaultProps}
|
|
322
|
+
onVerifyTotp={mockVerifyTotp}
|
|
323
|
+
onSuccess={mockOnSuccess}
|
|
324
|
+
/>
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
fireEvent.click(screen.getByTestId('login-password-btn'));
|
|
328
|
+
|
|
329
|
+
await waitFor(() => {
|
|
330
|
+
expect(screen.getByTestId('totp-verification-form')).toBeInTheDocument();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
fireEvent.click(screen.getByTestId('totp-submit-btn'));
|
|
334
|
+
|
|
335
|
+
await waitFor(() => {
|
|
336
|
+
expect(mockOnSuccess).toHaveBeenCalled();
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
@@ -1,21 +1,30 @@
|
|
|
1
|
+
// Re-export all wrapper components from their individual files
|
|
1
2
|
export { BackupCodeLoginWrapper } from './BackupCodeLoginWrapper';
|
|
2
3
|
export type { BackupCodeLoginWrapperProps } from './BackupCodeLoginWrapper';
|
|
4
|
+
|
|
3
5
|
export { BackupCodesWrapper } from './BackupCodesWrapper';
|
|
4
6
|
export type { BackupCodesWrapperProps } from './BackupCodesWrapper';
|
|
7
|
+
|
|
5
8
|
export { ChangePasswordFormWrapper } from './ChangePasswordFormWrapper';
|
|
6
9
|
export type { ChangePasswordFormWrapperProps } from './ChangePasswordFormWrapper';
|
|
10
|
+
|
|
7
11
|
export { ForgotPasswordFormWrapper } from './ForgotPasswordFormWrapper';
|
|
8
12
|
export type { ForgotPasswordFormWrapperProps } from './ForgotPasswordFormWrapper';
|
|
13
|
+
|
|
9
14
|
export { LoginFormWrapper } from './LoginFormWrapper';
|
|
10
15
|
export type { LoginFormWrapperProps } from './LoginFormWrapper';
|
|
16
|
+
|
|
11
17
|
export { RegisterFormWrapper } from './RegisterFormWrapper';
|
|
12
18
|
export type { RegisterFormWrapperProps } from './RegisterFormWrapper';
|
|
19
|
+
|
|
13
20
|
export { ResetPasswordFormWrapper } from './ResetPasswordFormWrapper';
|
|
14
21
|
export type { ResetPasswordFormWrapperProps } from './ResetPasswordFormWrapper';
|
|
22
|
+
|
|
15
23
|
export { LogoutPageWrapper } from './LogoutPageWrapper';
|
|
16
24
|
export type { LogoutPageWrapperProps } from './LogoutPageWrapper';
|
|
25
|
+
|
|
17
26
|
export { VerifyEmailPageWrapper } from './VerifyEmailPageWrapper';
|
|
18
27
|
export type { VerifyEmailPageWrapperProps } from './VerifyEmailPageWrapper';
|
|
28
|
+
|
|
19
29
|
export { UserSettingsFormWrapper } from './UserSettingsFormWrapper';
|
|
20
30
|
export type { UserSettingsFormWrapperProps } from './UserSettingsFormWrapper';
|
|
21
|
-
//# sourceMappingURL=index.d.ts.map
|
package/src/auth/AdminRoute.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AdminRoute.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/auth/AdminRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAWlD,UAAU,eAAe;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAmC1C,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
package/src/auth/AdminRoute.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AdminRoute = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const react_router_1 = require("react-router");
|
|
7
|
-
const AuthProvider_1 = require("../contexts/AuthProvider");
|
|
8
|
-
const contexts_1 = require("../contexts");
|
|
9
|
-
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
10
|
-
const AuthProvider_2 = require("../contexts/AuthProvider");
|
|
11
|
-
const AdminRoute = ({ children, redirectTo }) => {
|
|
12
|
-
const { admin } = (0, AuthProvider_2.useAuth)();
|
|
13
|
-
const { tComponent } = (0, contexts_1.useI18n)();
|
|
14
|
-
const { isAuthenticated, isCheckingAuth } = (0, react_1.useContext)(AuthProvider_1.AuthContext);
|
|
15
|
-
const location = (0, react_router_1.useLocation)();
|
|
16
|
-
if (isCheckingAuth) {
|
|
17
|
-
return ((0, jsx_runtime_1.jsxs)("div", { children: [tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_CheckingAuthentication), "..."] }));
|
|
18
|
-
}
|
|
19
|
-
if (!isAuthenticated) {
|
|
20
|
-
return ((0, jsx_runtime_1.jsx)(react_router_1.Navigate, { to: redirectTo ?? '/login', state: { from: location }, replace: true }));
|
|
21
|
-
}
|
|
22
|
-
if (!admin) {
|
|
23
|
-
return ((0, jsx_runtime_1.jsx)(react_router_1.Navigate, { to: redirectTo ?? '/', state: { from: location }, replace: true }));
|
|
24
|
-
}
|
|
25
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
26
|
-
};
|
|
27
|
-
exports.AdminRoute = AdminRoute;
|
|
28
|
-
exports.default = exports.AdminRoute;
|
package/src/auth/Private.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Private.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/auth/Private.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,YAAY,CAUpC,CAAC"}
|
package/src/auth/Private.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Private = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const AuthProvider_1 = require("../contexts/AuthProvider");
|
|
7
|
-
const Private = ({ children, }) => {
|
|
8
|
-
const { isAuthenticated, isCheckingAuth } = (0, react_1.useContext)(AuthProvider_1.AuthContext);
|
|
9
|
-
if (isCheckingAuth || !isAuthenticated) {
|
|
10
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
|
|
11
|
-
}
|
|
12
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
13
|
-
};
|
|
14
|
-
exports.Private = Private;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrivateRoute.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/auth/PrivateRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAMlD,UAAU,iBAAiB;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAc9C,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/src/auth/PrivateRoute.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrivateRoute = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const react_router_1 = require("react-router");
|
|
7
|
-
const AuthProvider_1 = require("../contexts/AuthProvider");
|
|
8
|
-
const contexts_1 = require("../contexts");
|
|
9
|
-
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
10
|
-
const PrivateRoute = ({ children, redirectTo }) => {
|
|
11
|
-
const { tComponent } = (0, contexts_1.useI18n)();
|
|
12
|
-
const { isAuthenticated, isCheckingAuth } = (0, react_1.useContext)(AuthProvider_1.AuthContext);
|
|
13
|
-
const location = (0, react_router_1.useLocation)();
|
|
14
|
-
if (isCheckingAuth) {
|
|
15
|
-
return (0, jsx_runtime_1.jsxs)("div", { children: [tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_CheckingAuthentication), "..."] });
|
|
16
|
-
}
|
|
17
|
-
if (!isAuthenticated) {
|
|
18
|
-
return (0, jsx_runtime_1.jsx)(react_router_1.Navigate, { to: redirectTo ?? "/login", state: { from: location }, replace: true });
|
|
19
|
-
}
|
|
20
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
21
|
-
};
|
|
22
|
-
exports.PrivateRoute = PrivateRoute;
|
|
23
|
-
exports.default = exports.PrivateRoute;
|
package/src/auth/UnAuth.d.ts
DELETED
package/src/auth/UnAuth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UnAuth.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/auth/UnAuth.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAGlD,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,WAAW,CAQlC,CAAC"}
|
package/src/auth/UnAuth.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnAuth = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const AuthProvider_1 = require("../contexts/AuthProvider");
|
|
7
|
-
const UnAuth = ({ children }) => {
|
|
8
|
-
const { isAuthenticated, isCheckingAuth } = (0, react_1.useContext)(AuthProvider_1.AuthContext);
|
|
9
|
-
if (isCheckingAuth || isAuthenticated) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
13
|
-
};
|
|
14
|
-
exports.UnAuth = UnAuth;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UnAuthRoute.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/auth/UnAuthRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAKlD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAiB5C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/src/auth/UnAuthRoute.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnAuthRoute = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const react_router_1 = require("react-router");
|
|
7
|
-
const contexts_1 = require("../contexts");
|
|
8
|
-
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
9
|
-
const UnAuthRoute = ({ children, redirectTo = '/dashboard', }) => {
|
|
10
|
-
const { isAuthenticated, isCheckingAuth } = (0, react_1.useContext)(contexts_1.AuthContext);
|
|
11
|
-
const { tComponent } = (0, contexts_1.useI18n)();
|
|
12
|
-
const location = (0, react_router_1.useLocation)();
|
|
13
|
-
if (isCheckingAuth) {
|
|
14
|
-
return (0, jsx_runtime_1.jsxs)("div", { children: [tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_CheckingAuthentication), "..."] });
|
|
15
|
-
}
|
|
16
|
-
if (isAuthenticated) {
|
|
17
|
-
return (0, jsx_runtime_1.jsx)(react_router_1.Navigate, { to: redirectTo ?? "/dashboard", state: { from: location }, replace: true });
|
|
18
|
-
}
|
|
19
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
20
|
-
};
|
|
21
|
-
exports.UnAuthRoute = UnAuthRoute;
|
|
22
|
-
exports.default = exports.UnAuthRoute;
|
package/src/auth/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAA"}
|
package/src/auth/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnAuthRoute = exports.PrivateRoute = exports.AdminRoute = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
var AdminRoute_1 = require("./AdminRoute");
|
|
6
|
-
Object.defineProperty(exports, "AdminRoute", { enumerable: true, get: function () { return tslib_1.__importDefault(AdminRoute_1).default; } });
|
|
7
|
-
var PrivateRoute_1 = require("./PrivateRoute");
|
|
8
|
-
Object.defineProperty(exports, "PrivateRoute", { enumerable: true, get: function () { return tslib_1.__importDefault(PrivateRoute_1).default; } });
|
|
9
|
-
var UnAuthRoute_1 = require("./UnAuthRoute");
|
|
10
|
-
Object.defineProperty(exports, "UnAuthRoute", { enumerable: true, get: function () { return tslib_1.__importDefault(UnAuthRoute_1).default; } });
|
|
11
|
-
tslib_1.__exportStar(require("./Private"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./UnAuth"), exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
export interface ApiAccessProps {
|
|
3
|
-
token?: string | null;
|
|
4
|
-
labels?: {
|
|
5
|
-
title?: string;
|
|
6
|
-
tokenNotAvailable?: string;
|
|
7
|
-
copyButton?: string;
|
|
8
|
-
notificationTitle?: string;
|
|
9
|
-
copied?: string;
|
|
10
|
-
copyFailed?: string;
|
|
11
|
-
ok?: string;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export declare const ApiAccess: FC<ApiAccessProps>;
|
|
15
|
-
export default ApiAccess;
|
|
16
|
-
//# sourceMappingURL=ApiAccess.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiAccess.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/components/ApiAccess.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAAE,EAAE,EAAY,MAAM,OAAO,CAAC;AA2BrC,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,CAmHxC,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiAccess = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
7
|
-
const ContentCopy_1 = tslib_1.__importDefault(require("@mui/icons-material/ContentCopy"));
|
|
8
|
-
const material_1 = require("@mui/material");
|
|
9
|
-
const react_1 = require("react");
|
|
10
|
-
const contexts_1 = require("../contexts");
|
|
11
|
-
const ApiAccessContainer = (0, material_1.styled)(material_1.Box)(({ theme }) => ({
|
|
12
|
-
display: 'flex',
|
|
13
|
-
flexDirection: 'column',
|
|
14
|
-
alignItems: 'center',
|
|
15
|
-
justifyContent: 'center',
|
|
16
|
-
minHeight: '100vh',
|
|
17
|
-
backgroundColor: theme.palette.background.default,
|
|
18
|
-
padding: theme.spacing(3),
|
|
19
|
-
}));
|
|
20
|
-
const ApiAccessContent = (0, material_1.styled)(material_1.Box)(({ theme }) => ({
|
|
21
|
-
maxWidth: '600px',
|
|
22
|
-
width: '100%',
|
|
23
|
-
backgroundColor: theme.palette.background.paper,
|
|
24
|
-
borderRadius: theme.shape.borderRadius,
|
|
25
|
-
padding: theme.spacing(4),
|
|
26
|
-
boxShadow: theme.shadows[3],
|
|
27
|
-
}));
|
|
28
|
-
const ApiAccessTitle = (0, material_1.styled)(material_1.Typography)(({ theme }) => ({
|
|
29
|
-
marginBottom: theme.spacing(3),
|
|
30
|
-
color: theme.palette.primary.main,
|
|
31
|
-
}));
|
|
32
|
-
const ApiAccess = ({ token: tokenProp, labels = {}, }) => {
|
|
33
|
-
const { token: authToken } = (0, contexts_1.useAuth)();
|
|
34
|
-
const token = tokenProp !== undefined ? tokenProp : authToken;
|
|
35
|
-
const { tComponent } = (0, contexts_1.useI18n)();
|
|
36
|
-
const [dialogOpen, setDialogOpen] = (0, react_1.useState)(false);
|
|
37
|
-
const [isError, setIsError] = (0, react_1.useState)(false);
|
|
38
|
-
const translatedLabels = {
|
|
39
|
-
title: labels.title ||
|
|
40
|
-
tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ApiAccess_Title),
|
|
41
|
-
tokenNotAvailable: labels.tokenNotAvailable ||
|
|
42
|
-
tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ApiAccess_TokenNotAvailable),
|
|
43
|
-
copyButton: labels.copyButton ||
|
|
44
|
-
tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_CopyToClipboard),
|
|
45
|
-
notificationTitle: labels.notificationTitle ||
|
|
46
|
-
tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Notification),
|
|
47
|
-
copied: labels.copied ||
|
|
48
|
-
tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_CopiedToClipboard),
|
|
49
|
-
copyFailed: labels.copyFailed ||
|
|
50
|
-
tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Error_FailedToCopy),
|
|
51
|
-
ok: labels.ok ||
|
|
52
|
-
tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_OK),
|
|
53
|
-
};
|
|
54
|
-
const copyToClipboard = async () => {
|
|
55
|
-
if (token) {
|
|
56
|
-
try {
|
|
57
|
-
await navigator.clipboard.writeText(token);
|
|
58
|
-
setIsError(false);
|
|
59
|
-
setDialogOpen(true);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
setIsError(true);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const handleClose = () => {
|
|
67
|
-
setDialogOpen(false);
|
|
68
|
-
setIsError(false);
|
|
69
|
-
};
|
|
70
|
-
return ((0, jsx_runtime_1.jsxs)(ApiAccessContainer, { children: [(0, jsx_runtime_1.jsxs)(ApiAccessContent, { children: [(0, jsx_runtime_1.jsx)(ApiAccessTitle, { variant: "h4", align: "center", children: translatedLabels.title }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, multiline: true, rows: 4, value: token || translatedLabels.tokenNotAvailable, slotProps: {
|
|
71
|
-
input: {
|
|
72
|
-
readOnly: true,
|
|
73
|
-
},
|
|
74
|
-
}, variant: "outlined", margin: "normal" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", color: "primary", startIcon: (0, jsx_runtime_1.jsx)(ContentCopy_1.default, {}), onClick: copyToClipboard, fullWidth: true, style: { marginTop: '16px' }, children: translatedLabels.copyButton })] }), (0, jsx_runtime_1.jsxs)(material_1.Dialog, { open: dialogOpen, onClose: handleClose, children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: translatedLabels.notificationTitle }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: isError ? translatedLabels.copyFailed : translatedLabels.copied }), (0, jsx_runtime_1.jsx)(material_1.DialogActions, { children: (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: handleClose, color: "primary", children: translatedLabels.ok }) })] })] }));
|
|
75
|
-
};
|
|
76
|
-
exports.ApiAccess = ApiAccess;
|
|
77
|
-
exports.default = exports.ApiAccess;
|