@micha.bigler/ui-core-micha 3.14.4 → 4.0.1
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/CHANGELOG.md +29 -0
- package/README.md +7 -0
- package/dist/chat/kitSxRegistry.js +9 -0
- package/dist/components/charts/kitSxRegistry.js +6 -0
- package/dist/entries/charts.js +6 -0
- package/dist/entries/chat.js +8 -0
- package/dist/entries/markdown.js +1 -0
- package/dist/index.js +0 -14
- package/dist/pages/AccountPage.js +1 -2
- package/dist/pages/LoginPage.js +1 -2
- package/dist/pages/PasswordChangePage.js +1 -2
- package/dist/pages/PasswordInvitePage.js +1 -2
- package/dist/pages/PasswordResetRequestPage.js +1 -2
- package/dist/pages/SignUpPage.js +1 -2
- package/dist/pages/SignupConfirmPage.js +1 -2
- package/dist/theme/kitSxEntry.js +11 -0
- package/dist/theme/kitSxRegistry.js +2 -15
- package/package.json +31 -7
- package/.github/workflows/ci.yml +0 -35
- package/.github/workflows/publish.yml +0 -126
- package/DESIGN.md +0 -60
- package/WORK_ORDERS.md +0 -150
- package/dev/entries.jsx +0 -721
- package/dev/fixtures.js +0 -26
- package/dev/main.jsx +0 -75
- package/dev/mockTransport.jsx +0 -128
- package/docs/CHART-LAYOUT.md +0 -157
- package/docs/DARK-TOKENS.md +0 -140
- package/docs/TYPE-SCALE.md +0 -111
- package/docs/messaging-deviations.md +0 -118
- package/index.html +0 -12
- package/renovate.json +0 -10
- package/scripts/chart-api-census.mjs +0 -415
- package/src/auth/AuthContext.jsx +0 -158
- package/src/auth/ReauthModal.jsx +0 -82
- package/src/auth/UserMenu.jsx +0 -121
- package/src/auth/apiClient.jsx +0 -232
- package/src/auth/authApi.jsx +0 -539
- package/src/auth/authConfig.jsx +0 -34
- package/src/auth/reauth.js +0 -47
- package/src/chat/ChatComposer.jsx +0 -36
- package/src/chat/ChatList.jsx +0 -87
- package/src/chat/ChatThread.jsx +0 -128
- package/src/chat/ChatWorkspace.jsx +0 -244
- package/src/chat/MarkdownReply.jsx +0 -22
- package/src/chat/ModelPicker.jsx +0 -85
- package/src/chat/api.js +0 -18
- package/src/chat/useChatSocket.js +0 -32
- package/src/chat/wire.js +0 -7
- package/src/components/AccessCodeManager.jsx +0 -288
- package/src/components/AccessCodeSingleUseToggle.jsx +0 -92
- package/src/components/AllowedEmailDomainsManager.jsx +0 -92
- package/src/components/AuthFactorRequirementCard.jsx +0 -95
- package/src/components/BulkInviteCsvTab.jsx +0 -198
- package/src/components/EmptyState.jsx +0 -38
- package/src/components/LoginForm.jsx +0 -159
- package/src/components/MFAComponent.jsx +0 -350
- package/src/components/MfaLoginComponent.jsx +0 -252
- package/src/components/MobileBottomNav.jsx +0 -82
- package/src/components/PasskeysComponent.jsx +0 -252
- package/src/components/PasswordChangeForm.jsx +0 -87
- package/src/components/PasswordResetRequestForm.jsx +0 -43
- package/src/components/PasswordSetForm.jsx +0 -97
- package/src/components/ProfileComponent.jsx +0 -348
- package/src/components/QrSignupManager.jsx +0 -404
- package/src/components/QrSignupValidityManager.jsx +0 -106
- package/src/components/RegistrationMethodsManager.jsx +0 -150
- package/src/components/SecurityComponent.jsx +0 -141
- package/src/components/SocialLoginButtons.jsx +0 -83
- package/src/components/SoftChip.jsx +0 -93
- package/src/components/StatTile.jsx +0 -39
- package/src/components/SupportRecoveryRequestsTab.jsx +0 -482
- package/src/components/TurnstileWidget.jsx +0 -99
- package/src/components/UserInviteComponent.jsx +0 -76
- package/src/components/UserListComponent.jsx +0 -618
- package/src/components/charts/BarChart.jsx +0 -102
- package/src/components/charts/ChartFrame.jsx +0 -214
- package/src/components/charts/LineChart.jsx +0 -126
- package/src/components/charts/ScatterChart.jsx +0 -299
- package/src/components/charts/TimeSeriesChart.jsx +0 -300
- package/src/components/charts/chartDefaults.js +0 -644
- package/src/components/charts/chartLabels.js +0 -36
- package/src/components/charts/exportChart.js +0 -258
- package/src/components/charts/formatters.js +0 -39
- package/src/components/charts/palette.js +0 -33
- package/src/components/charts/yearTickInterval.js +0 -7
- package/src/i18n/authTranslations.ts +0 -2651
- package/src/i18n/chartsTranslations.ts +0 -91
- package/src/i18n/chatTranslations.ts +0 -55
- package/src/i18n/messagingTranslations.ts +0 -120
- package/src/i18n/notificationsTranslations.ts +0 -32
- package/src/i18n/onboardingTranslations.ts +0 -29
- package/src/i18n/sectionNavTranslations.ts +0 -20
- package/src/i18n/uiCoreTranslations.js +0 -29
- package/src/i18n/userMenuTranslations.ts +0 -5
- package/src/index.js +0 -158
- package/src/layout/PageLayout.jsx +0 -36
- package/src/layout/SectionNav.jsx +0 -320
- package/src/messaging/AttachmentList.jsx +0 -145
- package/src/messaging/Composer.jsx +0 -197
- package/src/messaging/ConversationLaunchers.jsx +0 -51
- package/src/messaging/ConversationList.jsx +0 -109
- package/src/messaging/DirectMessageLauncher.jsx +0 -112
- package/src/messaging/MessageBubble.jsx +0 -183
- package/src/messaging/MessagingProvider.jsx +0 -0
- package/src/messaging/MessagingScopeConfig.jsx +0 -24
- package/src/messaging/PollCard.jsx +0 -163
- package/src/messaging/ReactionBar.jsx +0 -43
- package/src/messaging/ReadTicks.jsx +0 -82
- package/src/messaging/Thread.jsx +0 -195
- package/src/messaging/api.js +0 -48
- package/src/messaging/composerImageCompression.js +0 -35
- package/src/messaging/linkifyText.jsx +0 -37
- package/src/notifications/NotificationBell.jsx +0 -84
- package/src/notifications/NotificationSettings.jsx +0 -330
- package/src/notifications/NotificationsProvider.jsx +0 -224
- package/src/notifications/PopupSurface.jsx +0 -105
- package/src/notifications/api.js +0 -55
- package/src/notifications/feedApi.js +0 -18
- package/src/notifications/realtime.jsx +0 -138
- package/src/notifications/serviceWorker/sw.js +0 -50
- package/src/onboarding/OnboardingProvider.jsx +0 -326
- package/src/onboarding/OnboardingWizard.jsx +0 -61
- package/src/onboarding/WizardDialogShell.jsx +0 -51
- package/src/onboarding/api.js +0 -13
- package/src/onboarding/stepSelection.js +0 -16
- package/src/onboarding/steps/BrowserPushStep.jsx +0 -121
- package/src/onboarding/steps/CompleteNameStep.jsx +0 -46
- package/src/onboarding/steps/CookieConsentStep.jsx +0 -133
- package/src/onboarding/steps/PwaInstallStep.jsx +0 -47
- package/src/pages/AccountPage.jsx +0 -394
- package/src/pages/LoginPage.jsx +0 -343
- package/src/pages/PasswordChangePage.jsx +0 -62
- package/src/pages/PasswordInvitePage.jsx +0 -177
- package/src/pages/PasswordResetRequestPage.jsx +0 -68
- package/src/pages/SignUpPage.jsx +0 -268
- package/src/pages/SignupConfirmPage.jsx +0 -155
- package/src/testing/checkKitIntegration.js +0 -233
- package/src/theme/createAppTheme.js +0 -423
- package/src/theme/fonts.js +0 -3
- package/src/theme/index.js +0 -21
- package/src/theme/kitSxRegistry.js +0 -285
- package/src/theme/themeCompleteness.js +0 -1045
- package/src/theme/tokens.js +0 -478
- package/src/utils/auth-errors.js +0 -76
- package/src/utils/authService.js +0 -223
- package/src/utils/resolveErrorText.js +0 -28
- package/src/utils/webauthn.js +0 -51
- package/tests/AccountPage.profileStatements.test.jsx +0 -162
- package/tests/AccountPage.test.jsx +0 -200
- package/tests/AuthContext.test.jsx +0 -129
- package/tests/BarChart.test.jsx +0 -112
- package/tests/BrowserPushStep.test.jsx +0 -110
- package/tests/ChartFrame.test.jsx +0 -336
- package/tests/ConversationList.test.jsx +0 -144
- package/tests/CookieConsentStep.test.jsx +0 -69
- package/tests/EmptyState.test.jsx +0 -62
- package/tests/LineChart.test.jsx +0 -80
- package/tests/MessagingProvider.test.jsx +0 -50
- package/tests/MobileBottomNav.test.jsx +0 -319
- package/tests/NotificationBell.test.jsx +0 -60
- package/tests/NotificationSettings.test.jsx +0 -276
- package/tests/NotificationsProvider.test.jsx +0 -240
- package/tests/OnboardingProvider.test.jsx +0 -294
- package/tests/OnboardingWizard.test.jsx +0 -143
- package/tests/PasswordChangeForm.test.jsx +0 -70
- package/tests/PasswordInvitePage.test.jsx +0 -142
- package/tests/PasswordSetForm.test.jsx +0 -70
- package/tests/PopupSurface.test.jsx +0 -142
- package/tests/ProfileComponent.refresh.test.jsx +0 -194
- package/tests/QrSignupManager.registrationContext.test.jsx +0 -106
- package/tests/QrSignupManagerInfoBox.test.jsx +0 -49
- package/tests/ScatterChart.test.jsx +0 -270
- package/tests/SectionNav.test.jsx +0 -363
- package/tests/SignUpPage.test.jsx +0 -208
- package/tests/SoftChip.test.jsx +0 -105
- package/tests/StatTile.test.jsx +0 -57
- package/tests/Thread.test.jsx +0 -151
- package/tests/TimeSeriesChart.test.jsx +0 -367
- package/tests/UserListComponent.test.jsx +0 -192
- package/tests/UserMenu.test.jsx +0 -171
- package/tests/apiClientLanguage.test.js +0 -33
- package/tests/apiClientPublicPaths.test.js +0 -178
- package/tests/authApiLogin.test.js +0 -42
- package/tests/authApiRegistration.test.js +0 -31
- package/tests/authErrorCodeRendering.test.jsx +0 -77
- package/tests/authErrors.test.js +0 -74
- package/tests/authTranslations.test.js +0 -74
- package/tests/chart-api-census.test.js +0 -366
- package/tests/chartAxisTickBand.test.jsx +0 -95
- package/tests/chartDefaults.test.js +0 -902
- package/tests/chartLabels.test.js +0 -50
- package/tests/chartsPalette.test.js +0 -99
- package/tests/chatApi.test.js +0 -48
- package/tests/chatDriverNames.test.jsx +0 -71
- package/tests/chatExports.test.js +0 -3
- package/tests/chatList.test.jsx +0 -84
- package/tests/chatPicker.test.jsx +0 -82
- package/tests/chatSocket.test.jsx +0 -26
- package/tests/chatThread.test.jsx +0 -116
- package/tests/chatTranslations.test.js +0 -47
- package/tests/chatWorkspace.test.jsx +0 -234
- package/tests/checkKitIntegration.test.jsx +0 -219
- package/tests/createAppTheme.test.js +0 -132
- package/tests/createAppThemeDark.test.js +0 -127
- package/tests/createAppThemeLightGuard.test.js +0 -40
- package/tests/createAppThemePageContrast.test.js +0 -108
- package/tests/createAppThemeTypography.test.js +0 -53
- package/tests/errorCallSiteGuard.test.js +0 -32
- package/tests/exportChart.test.js +0 -313
- package/tests/feedApi.test.js +0 -46
- package/tests/fixtures/light-theme-baseline.json +0 -2234
- package/tests/i18nAggregate.test.js +0 -120
- package/tests/i18nGermanVariant.test.js +0 -65
- package/tests/loginPageErrorResolution.test.jsx +0 -102
- package/tests/messagingApi.test.js +0 -32
- package/tests/messagingChunk6.test.jsx +0 -116
- package/tests/messagingCompactBubble.test.jsx +0 -64
- package/tests/messagingComposer.test.jsx +0 -136
- package/tests/messagingComposerChunk5.test.jsx +0 -113
- package/tests/messagingContractConformance.test.js +0 -69
- package/tests/messagingDirectMessageLauncher.test.jsx +0 -151
- package/tests/messagingExports.test.js +0 -21
- package/tests/messagingInteractions.test.jsx +0 -136
- package/tests/messagingLastMessagePreview.test.jsx +0 -93
- package/tests/messagingLinkify.test.jsx +0 -51
- package/tests/messagingMessageActions.test.jsx +0 -163
- package/tests/messagingMsg6.test.jsx +0 -105
- package/tests/messagingMsg6f.test.jsx +0 -155
- package/tests/messagingMsg6g.test.jsx +0 -166
- package/tests/messagingMsg6h.test.jsx +0 -136
- package/tests/messagingMsg6i.test.jsx +0 -129
- package/tests/messagingPollRendering.test.jsx +0 -142
- package/tests/messagingReactionMerge.test.jsx +0 -77
- package/tests/messagingReadTicksTooltip.test.jsx +0 -36
- package/tests/messagingThreadReceipts.test.jsx +0 -178
- package/tests/messagingThreadingQuoting.test.jsx +0 -87
- package/tests/messagingUnreadLifecycle.test.jsx +0 -78
- package/tests/notificationsApi.test.js +0 -41
- package/tests/notificationsExports.test.js +0 -34
- package/tests/onboardingDescriptors.test.js +0 -132
- package/tests/packageTreeShaking.test.js +0 -126
- package/tests/realtime.test.jsx +0 -219
- package/tests/resolveErrorText.test.js +0 -72
- package/tests/stepSelection.test.js +0 -53
- package/tests/themeCompleteness.test.js +0 -626
- package/tests/timeSeriesLegend.test.js +0 -99
- package/tests/userScreenTranslations.test.jsx +0 -218
- package/tsconfig.build.json +0 -18
- package/vite.config.mjs +0 -6
- package/work-orders/AUTH-1.md +0 -74
- package/work-orders/AUTH-2.md +0 -74
- package/work-orders/AUTH-4.md +0 -183
- package/work-orders/AUTH-5.md +0 -154
- package/work-orders/AUTH-7.md +0 -181
- package/work-orders/AUTH-8.md +0 -184
- package/work-orders/CHART-1.md +0 -285
- package/work-orders/CHART-2.md +0 -222
- package/work-orders/CHART-3.md +0 -163
- package/work-orders/CHART-4.md +0 -203
- package/work-orders/CHART-5.md +0 -226
- package/work-orders/CHART-6.md +0 -428
- package/work-orders/CHART-7.md +0 -175
- package/work-orders/DX-1.md +0 -169
- package/work-orders/DX-2.md +0 -188
- package/work-orders/DX-3.md +0 -195
- package/work-orders/I18N-1.md +0 -254
- package/work-orders/I18N-3.md +0 -207
- package/work-orders/MSG-3.md +0 -375
- package/work-orders/MSG-3b.md +0 -1002
- package/work-orders/MSG-3c.md +0 -378
- package/work-orders/MSG-3d.md +0 -268
- package/work-orders/MSG-3e.md +0 -164
- package/work-orders/MSG-3f.md +0 -391
- package/work-orders/MSG-6e.md +0 -308
- package/work-orders/MSG-6f.md +0 -214
- package/work-orders/MSG-6g.md +0 -244
- package/work-orders/MSG-6h.md +0 -238
- package/work-orders/MSG-6i.md +0 -271
- package/work-orders/MSG-6j.md +0 -117
- package/work-orders/NOTIF-12.md +0 -214
- package/work-orders/NOTIF-13.md +0 -142
- package/work-orders/NOTIF-14.md +0 -151
- package/work-orders/PRIM-1.md +0 -177
- package/work-orders/SHELL-1.md +0 -255
- package/work-orders/SHELL-2.md +0 -197
- package/work-orders/SHELL-3.md +0 -359
- package/work-orders/SHELL-4.md +0 -351
- package/work-orders/SHELL-5.md +0 -345
- package/work-orders/SHELL-6.md +0 -210
- package/work-orders/THEME-1.md +0 -587
- package/work-orders/THEME-10.md +0 -303
- package/work-orders/THEME-11.md +0 -208
- package/work-orders/THEME-2.md +0 -339
- package/work-orders/THEME-3.md +0 -210
- package/work-orders/THEME-4.md +0 -271
- package/work-orders/THEME-5.md +0 -341
- package/work-orders/THEME-6.md +0 -247
- package/work-orders/THEME-7.md +0 -82
- package/work-orders/THEME-8.md +0 -211
- package/work-orders/THEME-9.md +0 -194
- package/work-orders/UCM-AUTH-10.md +0 -490
- package/work-orders/UCM-AUTH-11.md +0 -185
- package/work-orders/UCM-AUTH-12.md +0 -98
- package/work-orders/UCM-AUTH-13.md +0 -47
- package/work-orders/UCM-AUTH-9.md +0 -207
- package/work-orders/UCM-CHART-10.md +0 -150
- package/work-orders/UCM-CHART-11.md +0 -132
- package/work-orders/UCM-CHART-12.md +0 -348
- package/work-orders/UCM-CHART-13.md +0 -122
- package/work-orders/UCM-CHART-14.md +0 -198
- package/work-orders/UCM-CHART-15.md +0 -187
- package/work-orders/UCM-CHART-16.md +0 -169
- package/work-orders/UCM-CHART-17.md +0 -195
- package/work-orders/UCM-CHART-18.md +0 -200
- package/work-orders/UCM-CHART-8.md +0 -147
- package/work-orders/UCM-CHART-9.md +0 -265
- package/work-orders/UCM-CHAT-1.md +0 -190
- package/work-orders/UCM-CHAT-2.md +0 -75
- package/work-orders/UCM-CI-1.md +0 -65
- package/work-orders/UCM-DEP-1.md +0 -63
- package/work-orders/UCM-I18N-4.md +0 -226
- package/work-orders/UCM-I18N-5.md +0 -211
- package/work-orders/UCM-MSG-20.md +0 -192
- package/work-orders/UCM-PRIM-2.md +0 -114
- package/work-orders/UCM-SHELL-7.md +0 -134
- package/work-orders/UCM-SHELL-8.md +0 -125
- package/work-orders/UCM-TEST-1.md +0 -304
- package/work-orders/UCM-THEME-13.md +0 -69
- package/work-orders/UCM-THEME-14.md +0 -312
- package/work-orders/UCM-THEME-15.md +0 -356
- package/work-orders/UCM-THEME-16.md +0 -80
- package/work-orders/UCM-THEME-17.md +0 -111
- package/work-orders/UCM-THEME-18.md +0 -184
- package/work-orders/assets/AUTH-4-user-list-card.html +0 -407
- package/work-orders/assets/PRIM-1-dashboard-primitives.html +0 -624
- package/work-orders/assets/SHELL-2-account-navigation.html +0 -1159
- package/work-orders/assets/THEME-1-baseline-reference-sheet.html +0 -1352
- package/work-orders/assets/UCM-CHAT-1-ai-chat.html +0 -447
- package/work-orders/assets/UCM-THEME-13-dark-prototype.html +0 -390
- package/work-orders/assets/UCM-THEME-17-type-scale.html +0 -391
package/src/auth/AuthContext.jsx
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
// src/auth/AuthContext.jsx
|
|
2
|
-
import React, {
|
|
3
|
-
createContext,
|
|
4
|
-
useState,
|
|
5
|
-
useEffect,
|
|
6
|
-
} from 'react';
|
|
7
|
-
import { ensureCsrfToken } from './apiClient'; // <--- IMPORT ADDED
|
|
8
|
-
import {
|
|
9
|
-
fetchAuthMethods,
|
|
10
|
-
fetchCurrentUser,
|
|
11
|
-
logoutSession,
|
|
12
|
-
} from './authApi';
|
|
13
|
-
import { ReauthModal } from './ReauthModal';
|
|
14
|
-
|
|
15
|
-
export const AuthContext = createContext(null);
|
|
16
|
-
|
|
17
|
-
const DEFAULT_AUTH_METHODS = {
|
|
18
|
-
password_login: true,
|
|
19
|
-
password_reset: true,
|
|
20
|
-
signup: true,
|
|
21
|
-
signup_modes: ['self_signup_access_code'],
|
|
22
|
-
turnstile_site_key: '',
|
|
23
|
-
password_change: true,
|
|
24
|
-
social_login: true,
|
|
25
|
-
social_providers: ['google', 'microsoft'],
|
|
26
|
-
passkey_login: true,
|
|
27
|
-
passkeys_manage: true,
|
|
28
|
-
mfa_totp: true,
|
|
29
|
-
mfa_recovery_codes: true,
|
|
30
|
-
mfa_enabled: true,
|
|
31
|
-
required_auth_factor_count: 1,
|
|
32
|
-
two_factor_required: false,
|
|
33
|
-
qr_signup_enabled: false,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const AuthProvider = ({ children }) => {
|
|
37
|
-
const [user, setUser] = useState(null);
|
|
38
|
-
const [authMethods, setAuthMethods] = useState(DEFAULT_AUTH_METHODS);
|
|
39
|
-
const [loading, setLoading] = useState(true);
|
|
40
|
-
|
|
41
|
-
const mapUserFromApi = (data) => {
|
|
42
|
-
const profile = data?.profile || {};
|
|
43
|
-
return {
|
|
44
|
-
...data,
|
|
45
|
-
id: data?.id,
|
|
46
|
-
username: data?.username,
|
|
47
|
-
email: data?.email,
|
|
48
|
-
first_name: data?.first_name,
|
|
49
|
-
last_name: data?.last_name,
|
|
50
|
-
role: data?.role ?? profile?.role ?? null,
|
|
51
|
-
language: data?.language ?? profile?.language ?? 'en',
|
|
52
|
-
is_superuser: Boolean(data?.is_superuser),
|
|
53
|
-
is_new: Boolean(data?.is_new ?? profile?.is_new),
|
|
54
|
-
is_invited: Boolean(data?.is_invited ?? profile?.is_invited),
|
|
55
|
-
accepted_privacy_statement: Boolean(
|
|
56
|
-
data?.accepted_privacy_statement ?? profile?.accepted_privacy_statement
|
|
57
|
-
),
|
|
58
|
-
accepted_convenience_cookies: Boolean(
|
|
59
|
-
data?.accepted_convenience_cookies ?? profile?.accepted_convenience_cookies
|
|
60
|
-
),
|
|
61
|
-
is_support_agent: Boolean(data?.is_support_agent ?? profile?.is_support_agent),
|
|
62
|
-
support_contact_id: data?.support_contact_id ?? profile?.support_contact_id ?? null,
|
|
63
|
-
security_state: data?.security_state,
|
|
64
|
-
available_roles: data?.available_roles || [],
|
|
65
|
-
ui_permissions: data?.ui_permissions || {},
|
|
66
|
-
can_manage_support_agents: Boolean(data?.can_manage_support_agents),
|
|
67
|
-
can_manage: Boolean(data?.can_manage),
|
|
68
|
-
is_active: data?.is_active,
|
|
69
|
-
successful_login: Boolean(data?.successful_login ?? data?.last_login),
|
|
70
|
-
last_login: data?.last_login,
|
|
71
|
-
date_joined: data?.date_joined,
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
let isMounted = true;
|
|
77
|
-
|
|
78
|
-
const initAuth = async () => {
|
|
79
|
-
try {
|
|
80
|
-
// 1) Ensure CSRF cookie exists using the specific client
|
|
81
|
-
await ensureCsrfToken();
|
|
82
|
-
|
|
83
|
-
// 2) Both calls depend on CSRF, but not on each other. Await both settlements
|
|
84
|
-
// so loading stays true until the complete auth bootstrap has finished.
|
|
85
|
-
const [methodsResult, userResult] = await Promise.allSettled([
|
|
86
|
-
fetchAuthMethods(),
|
|
87
|
-
fetchCurrentUser(),
|
|
88
|
-
]);
|
|
89
|
-
|
|
90
|
-
// Keep defaults when the public auth-methods request fails.
|
|
91
|
-
if (methodsResult.status === 'fulfilled') {
|
|
92
|
-
const methods = methodsResult.value;
|
|
93
|
-
if (isMounted && methods && typeof methods === 'object') {
|
|
94
|
-
setAuthMethods((prev) => ({ ...prev, ...methods }));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Preserve the previous unauthenticated/error handling for current-user.
|
|
99
|
-
if (userResult.status === 'rejected') {
|
|
100
|
-
throw userResult.reason;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const data = userResult.value;
|
|
104
|
-
if (isMounted) {
|
|
105
|
-
setUser(mapUserFromApi(data));
|
|
106
|
-
}
|
|
107
|
-
} catch (err) {
|
|
108
|
-
// Silent failure on 401/403 is expected (user not logged in)
|
|
109
|
-
if (isMounted) setUser(null);
|
|
110
|
-
} finally {
|
|
111
|
-
if (isMounted) setLoading(false);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
initAuth();
|
|
116
|
-
|
|
117
|
-
return () => { isMounted = false; };
|
|
118
|
-
}, []);
|
|
119
|
-
|
|
120
|
-
const login = (userData) => {
|
|
121
|
-
setUser((prev) => ({
|
|
122
|
-
...prev,
|
|
123
|
-
...mapUserFromApi(userData),
|
|
124
|
-
}));
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const refreshUser = async () => {
|
|
128
|
-
const data = await fetchCurrentUser();
|
|
129
|
-
if (data) setUser(mapUserFromApi(data));
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const logout = async () => {
|
|
133
|
-
try {
|
|
134
|
-
await logoutSession();
|
|
135
|
-
} catch (error) {
|
|
136
|
-
// eslint-disable-next-line no-console
|
|
137
|
-
console.error('Error during logout:', error);
|
|
138
|
-
} finally {
|
|
139
|
-
setUser(null);
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return (
|
|
144
|
-
<AuthContext.Provider
|
|
145
|
-
value={{
|
|
146
|
-
user,
|
|
147
|
-
authMethods,
|
|
148
|
-
loading,
|
|
149
|
-
login,
|
|
150
|
-
logout,
|
|
151
|
-
refreshUser,
|
|
152
|
-
}}
|
|
153
|
-
>
|
|
154
|
-
{children}
|
|
155
|
-
<ReauthModal />
|
|
156
|
-
</AuthContext.Provider>
|
|
157
|
-
);
|
|
158
|
-
};
|
package/src/auth/ReauthModal.jsx
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Alert,
|
|
4
|
-
Button,
|
|
5
|
-
Dialog,
|
|
6
|
-
DialogActions,
|
|
7
|
-
DialogContent,
|
|
8
|
-
DialogTitle,
|
|
9
|
-
TextField,
|
|
10
|
-
} from '@mui/material';
|
|
11
|
-
import { useTranslation } from 'react-i18next';
|
|
12
|
-
import apiClient from './apiClient';
|
|
13
|
-
import { HEADLESS_BASE } from './authConfig';
|
|
14
|
-
import { rejectReauth, resolveReauth, subscribe } from './reauth';
|
|
15
|
-
|
|
16
|
-
export const REAUTH_MODAL_ALERT_SX = { mb: 2 };
|
|
17
|
-
export const REAUTH_MODAL_TEXT_FIELD_SX = { mt: 1 };
|
|
18
|
-
|
|
19
|
-
export function ReauthModal() {
|
|
20
|
-
const { t } = useTranslation();
|
|
21
|
-
const [open, setOpen] = useState(false);
|
|
22
|
-
const [password, setPassword] = useState('');
|
|
23
|
-
const [loading, setLoading] = useState(false);
|
|
24
|
-
const [error, setError] = useState(null);
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
return subscribe((active) => {
|
|
28
|
-
setOpen(active);
|
|
29
|
-
if (!active) {
|
|
30
|
-
setPassword('');
|
|
31
|
-
setError(null);
|
|
32
|
-
setLoading(false);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
const handleSubmit = async (e) => {
|
|
38
|
-
e.preventDefault();
|
|
39
|
-
setLoading(true);
|
|
40
|
-
setError(null);
|
|
41
|
-
try {
|
|
42
|
-
await apiClient.post(`${HEADLESS_BASE}/auth/reauthenticate`, { password });
|
|
43
|
-
resolveReauth();
|
|
44
|
-
} catch {
|
|
45
|
-
setError(t('Auth.REAUTH_FAILED'));
|
|
46
|
-
setLoading(false);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const handleCancel = () => {
|
|
51
|
-
rejectReauth(new Error('cancelled'));
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<Dialog open={open} onClose={handleCancel} maxWidth="xs" fullWidth>
|
|
56
|
-
<form onSubmit={handleSubmit}>
|
|
57
|
-
<DialogTitle>{t('Auth.REAUTH_TITLE')}</DialogTitle>
|
|
58
|
-
<DialogContent>
|
|
59
|
-
{error && <Alert severity="error" sx={REAUTH_MODAL_ALERT_SX}>{error}</Alert>}
|
|
60
|
-
<TextField
|
|
61
|
-
autoFocus
|
|
62
|
-
fullWidth
|
|
63
|
-
type="password"
|
|
64
|
-
label={t('Auth.LOGIN_PASSWORD_LABEL')}
|
|
65
|
-
value={password}
|
|
66
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
67
|
-
disabled={loading}
|
|
68
|
-
sx={REAUTH_MODAL_TEXT_FIELD_SX}
|
|
69
|
-
/>
|
|
70
|
-
</DialogContent>
|
|
71
|
-
<DialogActions>
|
|
72
|
-
<Button onClick={handleCancel} disabled={loading}>
|
|
73
|
-
{t('Auth.MFA_TOTP_CANCEL_BUTTON')}
|
|
74
|
-
</Button>
|
|
75
|
-
<Button type="submit" variant="contained" disabled={loading || !password}>
|
|
76
|
-
{loading ? t('Auth.MFA_TOTP_VERIFY_BUTTON_LOADING') : t('Auth.MFA_VERIFY')}
|
|
77
|
-
</Button>
|
|
78
|
-
</DialogActions>
|
|
79
|
-
</form>
|
|
80
|
-
</Dialog>
|
|
81
|
-
);
|
|
82
|
-
}
|
package/src/auth/UserMenu.jsx
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { useContext, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Avatar,
|
|
5
|
-
Box,
|
|
6
|
-
Divider,
|
|
7
|
-
IconButton,
|
|
8
|
-
Menu,
|
|
9
|
-
MenuItem,
|
|
10
|
-
Typography,
|
|
11
|
-
} from '@mui/material';
|
|
12
|
-
import { useTheme } from '@mui/material/styles';
|
|
13
|
-
import { useTranslation } from 'react-i18next';
|
|
14
|
-
|
|
15
|
-
import { AuthContext } from './AuthContext';
|
|
16
|
-
import { calculateContrastRatio } from '../theme';
|
|
17
|
-
|
|
18
|
-
function getInitials(user) {
|
|
19
|
-
if (!user) return '';
|
|
20
|
-
const first = user.first_name?.trim()?.[0];
|
|
21
|
-
const last = user.last_name?.trim()?.[0];
|
|
22
|
-
if (first || last) return `${first || ''}${last || ''}`.toUpperCase();
|
|
23
|
-
return (user.username?.trim()?.[0] || '').toUpperCase();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function getDisplayName(user) {
|
|
27
|
-
if (!user) return '';
|
|
28
|
-
const name = `${user.first_name || ''} ${user.last_name || ''}`.trim();
|
|
29
|
-
return name || user.username || '';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function UserMenu({ resolveLink, items = [], profileLink = '/account', avatarSrc }) {
|
|
33
|
-
const { t } = useTranslation();
|
|
34
|
-
const { user, logout } = useContext(AuthContext);
|
|
35
|
-
const theme = useTheme();
|
|
36
|
-
const [anchorEl, setAnchorEl] = useState(null);
|
|
37
|
-
const open = Boolean(anchorEl);
|
|
38
|
-
const avatarBackground = theme.palette.primary.main;
|
|
39
|
-
// True white/black (theme.palette.common.*, always present on any MUI theme,
|
|
40
|
-
// never a source-level literal), not background.paper/ink.primary: contrast
|
|
41
|
-
// against true white and true black multiplies to a constant 21 regardless
|
|
42
|
-
// of the background's luminance, so max(contrastWhite, contrastBlack) is
|
|
43
|
-
// mathematically guaranteed to be >= sqrt(21) =~ 4.58 for ANY primary.main a
|
|
44
|
-
// consumer sets -- a near-black token like ink.primary (#212529, luminance
|
|
45
|
-
// ~0.018, not 0) does not carry that guarantee and left a real gap for a
|
|
46
|
-
// medium-luminance primary (caught by ui_reviewer, neither required test
|
|
47
|
-
// exercised the fallback branch that gap lived in).
|
|
48
|
-
const avatarText = calculateContrastRatio(theme.palette.common.white, avatarBackground) >= 4.5
|
|
49
|
-
? theme.palette.common.white
|
|
50
|
-
: theme.palette.common.black;
|
|
51
|
-
|
|
52
|
-
const handleClose = () => setAnchorEl(null);
|
|
53
|
-
|
|
54
|
-
const handleProfile = () => {
|
|
55
|
-
handleClose();
|
|
56
|
-
resolveLink?.(profileLink);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const handleLogout = () => {
|
|
60
|
-
handleClose();
|
|
61
|
-
logout();
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const handleItemSelect = (item) => {
|
|
65
|
-
handleClose();
|
|
66
|
-
item.onSelect?.();
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<>
|
|
71
|
-
<IconButton
|
|
72
|
-
aria-label={t('UserMenu.TITLE')}
|
|
73
|
-
color="inherit"
|
|
74
|
-
onClick={(event) => setAnchorEl(event.currentTarget)}
|
|
75
|
-
>
|
|
76
|
-
<Avatar
|
|
77
|
-
src={avatarSrc}
|
|
78
|
-
sx={{
|
|
79
|
-
width: 32,
|
|
80
|
-
height: 32,
|
|
81
|
-
fontSize: '0.8rem',
|
|
82
|
-
bgcolor: avatarBackground,
|
|
83
|
-
color: avatarText,
|
|
84
|
-
}}
|
|
85
|
-
>
|
|
86
|
-
{avatarSrc ? null : getInitials(user)}
|
|
87
|
-
</Avatar>
|
|
88
|
-
</IconButton>
|
|
89
|
-
<Menu
|
|
90
|
-
anchorEl={anchorEl}
|
|
91
|
-
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
|
|
92
|
-
onClose={handleClose}
|
|
93
|
-
open={open}
|
|
94
|
-
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
|
|
95
|
-
>
|
|
96
|
-
<Box sx={{ minWidth: 240, px: 2, py: 1 }}>
|
|
97
|
-
<Typography variant="subtitle1" noWrap>{getDisplayName(user)}</Typography>
|
|
98
|
-
{/* A user with no first/last name falls back to username as the
|
|
99
|
-
display name above — some hosts' usernames are the email
|
|
100
|
-
address itself, which would otherwise repeat the same text
|
|
101
|
-
on both lines. */}
|
|
102
|
-
{user?.email && user.email !== getDisplayName(user) && (
|
|
103
|
-
<Typography variant="body2" color="text.secondary" noWrap>{user.email}</Typography>
|
|
104
|
-
)}
|
|
105
|
-
</Box>
|
|
106
|
-
<Divider />
|
|
107
|
-
<MenuItem onClick={handleProfile}>{t('UserMenu.PROFILE')}</MenuItem>
|
|
108
|
-
{items.length > 0 && <Divider />}
|
|
109
|
-
{items.map((item) => (
|
|
110
|
-
<MenuItem key={item.id} onClick={() => handleItemSelect(item)}>
|
|
111
|
-
{item.label}
|
|
112
|
-
</MenuItem>
|
|
113
|
-
))}
|
|
114
|
-
<Divider />
|
|
115
|
-
<MenuItem onClick={handleLogout}>{t('UserMenu.LOGOUT')}</MenuItem>
|
|
116
|
-
</Menu>
|
|
117
|
-
</>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export default UserMenu;
|
package/src/auth/apiClient.jsx
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import i18next from "i18next";
|
|
3
|
-
import { CSRF_URL } from "./authConfig";
|
|
4
|
-
import { requestReauth } from "./reauth";
|
|
5
|
-
|
|
6
|
-
const apiClient = axios.create({
|
|
7
|
-
withCredentials: true,
|
|
8
|
-
xsrfCookieName: "csrftoken",
|
|
9
|
-
xsrfHeaderName: "X-CSRFToken",
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
apiClient.interceptors.request.use((config) => {
|
|
13
|
-
const language = i18next?.isInitialized ? i18next.language : null;
|
|
14
|
-
if (language) {
|
|
15
|
-
config.headers = { ...config.headers, 'Accept-Language': language };
|
|
16
|
-
}
|
|
17
|
-
return config;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
let redirectingToLogin = false;
|
|
21
|
-
|
|
22
|
-
function isBrowser() {
|
|
23
|
-
return typeof window !== "undefined";
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Routen, die OHNE Login funktionieren müssen. Library-eigene Pfade sind eingefroren
|
|
27
|
-
// und können nicht entfernt werden — sonst würde z. B. `removePublicPath("/login")`
|
|
28
|
-
// auf der Login-Page selbst einen Redirect-Loop auslösen.
|
|
29
|
-
const BUILTIN_PUBLIC_PATHS = Object.freeze([
|
|
30
|
-
"/login",
|
|
31
|
-
"/signup",
|
|
32
|
-
"/reset-request-password",
|
|
33
|
-
"/invite", // /invite/:uid/:token
|
|
34
|
-
"/reset", // /reset/:uid/:token
|
|
35
|
-
"/welcome",
|
|
36
|
-
]);
|
|
37
|
-
|
|
38
|
-
const CONSUMER_PUBLIC_PATHS = new Set();
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Register an additional public path so a 401 on that route does not auto-redirect
|
|
42
|
-
* to `/login`. Typical use: a public landing on `/` in an otherwise authenticated app.
|
|
43
|
-
*
|
|
44
|
-
* Accepts a `string` (matched like the builtins: exact for "/", prefix otherwise) or
|
|
45
|
-
* a `RegExp` (AUTH-5) for consumers whose public area includes a dynamic segment —
|
|
46
|
-
* e.g. `/<slug>`, `/<slug>/team` — that no finite set of string prefixes can describe.
|
|
47
|
-
*
|
|
48
|
-
* A `RegExp` is tested via `.test()` against `window.location.pathname` ONLY — never
|
|
49
|
-
* against the query string or fragment. Anchor it (`^…$`): this library does not add
|
|
50
|
-
* anchors for you, and an unanchored pattern like `/team` also matches `/admin/team`,
|
|
51
|
-
* silently suppressing the redirect somewhere it's still needed. That failure is
|
|
52
|
-
* invisible until someone opens the over-matched page anonymously and lands on a
|
|
53
|
-
* blank error instead of `/login` — so test the non-matching direction too, not just
|
|
54
|
-
* the intended match.
|
|
55
|
-
*
|
|
56
|
-
* MUST be called before the AuthProvider mounts (i.e. before `ReactDOM.render`).
|
|
57
|
-
* Calling it later won't help the bootstrap probe which fires on AuthProvider mount.
|
|
58
|
-
*/
|
|
59
|
-
export function addPublicPath(path) {
|
|
60
|
-
if (typeof path === "string" && path) {
|
|
61
|
-
CONSUMER_PUBLIC_PATHS.add(path);
|
|
62
|
-
} else if (path instanceof RegExp) {
|
|
63
|
-
CONSUMER_PUBLIC_PATHS.add(path);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Remove a consumer-added public path. Library-internal paths are protected.
|
|
69
|
-
*
|
|
70
|
-
* For a `RegExp` entry, removal is by object identity (`Set.delete` uses SameValueZero
|
|
71
|
-
* equality) — pass the exact same `RegExp` instance `addPublicPath` was given, not a
|
|
72
|
-
* new literal that merely looks the same. Two `/^\/team$/` literals are not equal.
|
|
73
|
-
*/
|
|
74
|
-
export function removePublicPath(path) {
|
|
75
|
-
CONSUMER_PUBLIC_PATHS.delete(path);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function isPublicSitePath(pathname) {
|
|
79
|
-
return pathname === "/sites" || pathname.startsWith("/sites/");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Match rule: a RegExp entry is tested against pathname only (AUTH-5). A string entry
|
|
83
|
-
// of exactly "/" requires strict equality (avoids matching every path with
|
|
84
|
-
// startsWith); other string entries keep the looser prefix match so dynamic routes
|
|
85
|
-
// like /invite/:uid/:token still work.
|
|
86
|
-
function matchesPublicPath(pathname, entry) {
|
|
87
|
-
if (entry instanceof RegExp) {
|
|
88
|
-
// `g`/`y` flags make `.test()` stateful (`lastIndex` advances on match), which would
|
|
89
|
-
// make the same pathname alternate matched/unmatched across calls to this
|
|
90
|
-
// long-lived, module-scoped RegExp — a redirect that only fires every other time.
|
|
91
|
-
// Reset before every test so a consumer's flags can't leak state across calls.
|
|
92
|
-
entry.lastIndex = 0;
|
|
93
|
-
return entry.test(pathname);
|
|
94
|
-
}
|
|
95
|
-
if (entry === "/") return pathname === "/";
|
|
96
|
-
return pathname.startsWith(entry);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function redirectToLoginOnce() {
|
|
100
|
-
if (!isBrowser()) return;
|
|
101
|
-
|
|
102
|
-
const currentPath = window.location.pathname;
|
|
103
|
-
|
|
104
|
-
const isPublicPage =
|
|
105
|
-
isPublicSitePath(currentPath) ||
|
|
106
|
-
BUILTIN_PUBLIC_PATHS.some((path) => matchesPublicPath(currentPath, path)) ||
|
|
107
|
-
Array.from(CONSUMER_PUBLIC_PATHS).some((path) => matchesPublicPath(currentPath, path));
|
|
108
|
-
|
|
109
|
-
// Wenn ja: NICHT weiterleiten. Der 401 Fehler wird an die Komponente durchgereicht.
|
|
110
|
-
if (isPublicPage) return;
|
|
111
|
-
|
|
112
|
-
if (redirectingToLogin) return;
|
|
113
|
-
|
|
114
|
-
redirectingToLogin = true;
|
|
115
|
-
|
|
116
|
-
// Wir speichern die aktuelle Seite, um nach dem Login zurückzukehren
|
|
117
|
-
// (außer wir sind schon auf Login)
|
|
118
|
-
if (!currentPath.startsWith("/login")) {
|
|
119
|
-
// Optional: ?next=... Logik
|
|
120
|
-
// window.location.assign(`/login?next=${encodeURIComponent(currentPath)}`);
|
|
121
|
-
window.location.assign("/login");
|
|
122
|
-
} else {
|
|
123
|
-
window.location.assign("/login");
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function extractAuthSignal(data) {
|
|
128
|
-
if (!data) {
|
|
129
|
-
return { code: null, i18nKey: null };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (typeof data === "string") {
|
|
133
|
-
try {
|
|
134
|
-
const parsed = JSON.parse(data);
|
|
135
|
-
return extractAuthSignal(parsed);
|
|
136
|
-
} catch {
|
|
137
|
-
return { code: null, i18nKey: null };
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (typeof data !== "object") {
|
|
142
|
-
return { code: null, i18nKey: null };
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (typeof data.code === "string" || typeof data.i18nKey === "string") {
|
|
146
|
-
return {
|
|
147
|
-
code: typeof data.code === "string" ? data.code : null,
|
|
148
|
-
i18nKey: typeof data.i18nKey === "string" ? data.i18nKey : null,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (Array.isArray(data.errors) && data.errors.length > 0) {
|
|
153
|
-
const first = data.errors[0] || {};
|
|
154
|
-
return {
|
|
155
|
-
code: typeof first.code === "string" ? first.code : null,
|
|
156
|
-
i18nKey: typeof first.i18nKey === "string" ? first.i18nKey : null,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (data.detail && typeof data.detail === "object") {
|
|
161
|
-
return {
|
|
162
|
-
code: typeof data.detail.code === "string" ? data.detail.code : null,
|
|
163
|
-
i18nKey: typeof data.detail.i18nKey === "string" ? data.detail.i18nKey : null,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return { code: null, i18nKey: null };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
apiClient.interceptors.response.use(
|
|
171
|
-
(response) => response,
|
|
172
|
-
async (error) => {
|
|
173
|
-
const status = error?.response?.status ?? null;
|
|
174
|
-
const data = error?.response?.data ?? {};
|
|
175
|
-
const { code, i18nKey } = extractAuthSignal(data);
|
|
176
|
-
|
|
177
|
-
const isAuthStatus = status === 401 || status === 403;
|
|
178
|
-
const isNotAuthenticated =
|
|
179
|
-
code === "not_authenticated" || i18nKey === "auth.not_authenticated";
|
|
180
|
-
|
|
181
|
-
// Reauthentication gate: allauth returns 401 + flows[{id:"reauthenticate"}]
|
|
182
|
-
// when the session is stale before a sensitive operation (e.g. adding a passkey).
|
|
183
|
-
// Show the password-confirm modal, wait for it to complete, then retry once.
|
|
184
|
-
const flows = data?.data?.flows ?? data?.flows ?? [];
|
|
185
|
-
const needsReauth =
|
|
186
|
-
status === 401 &&
|
|
187
|
-
Array.isArray(flows) &&
|
|
188
|
-
flows.some((f) => f.id === "reauthenticate");
|
|
189
|
-
|
|
190
|
-
if (needsReauth && !error.config?._reauthRetried) {
|
|
191
|
-
try {
|
|
192
|
-
await requestReauth();
|
|
193
|
-
return apiClient({ ...error.config, _reauthRetried: true });
|
|
194
|
-
} catch {
|
|
195
|
-
return Promise.reject(error);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Per-request opt-out: bootstrap probes (e.g. fetchCurrentUser on app start)
|
|
200
|
-
// expect to handle 401 silently and must not trigger a redirect-on-mount.
|
|
201
|
-
// Carried as an axios config property, so it never travels to the backend
|
|
202
|
-
// (would otherwise trigger a CORS preflight on cross-origin requests).
|
|
203
|
-
const skipRedirect = error?.config?.skipAuthRedirect === true;
|
|
204
|
-
|
|
205
|
-
if (isAuthStatus && isNotAuthenticated && !skipRedirect) {
|
|
206
|
-
redirectToLoginOnce();
|
|
207
|
-
}
|
|
208
|
-
return Promise.reject(error);
|
|
209
|
-
}
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
function getCookie(name) {
|
|
213
|
-
if (!isBrowser() || !document.cookie) return null;
|
|
214
|
-
const xsrfCookies = document.cookie.split(';')
|
|
215
|
-
.map(c => c.trim())
|
|
216
|
-
.filter(c => c.startsWith(name + '='));
|
|
217
|
-
if (xsrfCookies.length === 0) return null;
|
|
218
|
-
return decodeURIComponent(xsrfCookies[0].split('=')[1]);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export async function ensureCsrfToken() {
|
|
222
|
-
if (getCookie("csrftoken")) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
try {
|
|
226
|
-
await apiClient.get(CSRF_URL);
|
|
227
|
-
} catch (err) {
|
|
228
|
-
console.warn("CSRF Initialization failed", err);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export default apiClient;
|