@micha.bigler/ui-core-micha 4.12.0 → 4.13.0
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 +15 -0
- package/README.md +56 -0
- package/dist/auth/termsApi.js +12 -0
- package/dist/billing/api.js +29 -1
- package/dist/billing/wire.js +1 -0
- package/dist/components/LoginContent.js +293 -0
- package/dist/components/ProfileComponent.js +12 -30
- package/dist/components/ProfileStepContent.js +237 -0
- package/dist/components/SignUpContent.js +155 -0
- package/dist/components/SignupConfirmContent.js +62 -0
- package/dist/i18n/authTranslations.js +96 -0
- package/dist/i18n/onboardingTranslations.js +2 -0
- package/dist/index.js +7 -1
- package/dist/onboarding/SetupWizardShell.js +114 -0
- package/dist/pages/LoginPage.js +7 -250
- package/dist/pages/SignUpPage.js +13 -97
- package/dist/pages/SignupConfirmPage.js +13 -50
- package/dist/theme/kitSxRegistry.js +13 -0
- package/dist/utils/continuation.js +48 -0
- package/dist/utils/profileDraft.js +22 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.13.0 - UCM-AUTH-14
|
|
4
|
+
|
|
5
|
+
Composable account and profile steps for a page-based setup wizard; all additive. New exports: `SetupWizardShell`
|
|
6
|
+
(host-controlled single-column frame with step list, title, error, content and one action row), `SignUpContent`,
|
|
7
|
+
`SignupConfirmContent`, `LoginContent` (the existing page controllers without page framing; `LoginPage`, `SignUpPage`
|
|
8
|
+
and `SignupConfirmPage` now wrap them and behave as before), `ProfileStepContent` (names, one required statement,
|
|
9
|
+
optional convenience cookies, host draft bound to the person), `createTermsApi` / `defaultTermsApi`, and
|
|
10
|
+
`createCheckoutIdempotencyKey`. `createBillingApi()` gains `startCheckout(planKey, { context, idempotencyKey })` and
|
|
11
|
+
`resolveCheckoutAttempt(reference)`; `startCheckout(planKey)` sends exactly `{ plan_key }` as before. Terms acceptance
|
|
12
|
+
and contextual checkout require `django-core-micha` >= 3.16.0; everything else works with the existing DCM versions.
|
|
13
|
+
Continuations are same-origin paths only and never bypass recovery or required-security redirects. New keys
|
|
14
|
+
`Auth.PROVIDER_TRANSITION`, `CONFIRMATION_EMAIL_INSTRUCTION`, `TERMS_*`, `PRIVACY_*`, `CONVENIENCE_COOKIES_LABEL`,
|
|
15
|
+
`PROFILE_NAME_REQUIRED`, `Onboarding.COMPLETED`, `Onboarding.BACK` (de, de_informal where it addresses the person, en,
|
|
16
|
+
fr, sw). The dev harness has a `setup-wizard` entry (`#setup-wizard` opens it alone at the browser viewport).
|
|
17
|
+
|
|
3
18
|
## 4.12.0 - UCM-BILL-8
|
|
4
19
|
|
|
5
20
|
`SubscriptionSection` accepts an optional `onChoosePlan` callback for apps that have their own plan page. With it, the
|
package/README.md
CHANGED
|
@@ -30,6 +30,62 @@ phone navigation. Without `group`, or with `more` or an unknown value, it stays
|
|
|
30
30
|
`onChoosePlan()` (the banner's renew action calls it too, and wins over `onRenew`), and no inline picker. Without the
|
|
31
31
|
prop the section behaves as before.
|
|
32
32
|
|
|
33
|
+
## Setup wizard: account and profile steps
|
|
34
|
+
|
|
35
|
+
For a page-based first-use flow (UCM-AUTH-14). The host owns the journey: which steps exist, which are completed or
|
|
36
|
+
reachable, navigation, busy state, errors, every draft and any persistence. The kit stores nothing and starts no
|
|
37
|
+
project, import or payment work. Existing pages and the dialog `OnboardingProvider` / `OnboardingWizard` are unchanged.
|
|
38
|
+
|
|
39
|
+
- `SetupWizardShell` — one column of stable width: labelled step list, "Schritt n von N", title (`title`, default the
|
|
40
|
+
step label), optional `description`, `error` alert, the step content and one action row (`onBack` / `backLabel`,
|
|
41
|
+
`primaryLabel` with `onPrimary` or `primaryForm`). Props `steps` (`[{ id, label }]`), `currentStepId`,
|
|
42
|
+
`completedStepIds`, `reachableStepIds`, `onSelectStep`, `busy`. `onPrimary` may return a promise; the action is
|
|
43
|
+
ignored until it settles. `primaryForm` names a form in the content that the primary button submits natively.
|
|
44
|
+
- `SignUpContent` — the sign-up form of `SignUpPage` (all modes, Turnstile, QR token via `registrationContextToken`).
|
|
45
|
+
`onSubmitted(email)` switches it to the confirmation instruction; remount it (new `key`) to let the person change the
|
|
46
|
+
email. `showProviders` adds Google/Microsoft above the form.
|
|
47
|
+
- `SignupConfirmContent` — the password form of `SignupConfirmPage`. Pass `token` (from the emailed
|
|
48
|
+
`/signup/confirm/?token=…` link, which your app routes) and `onSuccess()`; there is no automatic sign-in, show
|
|
49
|
+
`LoginContent` next.
|
|
50
|
+
- `LoginContent` — the controller of `LoginPage` without page framing, MFA inline. `onSuccess({ user, target })`; when
|
|
51
|
+
recovery or required additional security applies it navigates to the security page itself and does not call
|
|
52
|
+
`onSuccess`. `onSignUp` and `onForgotPassword` show those buttons.
|
|
53
|
+
- `ProfileStepContent` — names, one required statement and optional convenience cookies; `onComplete(user)` only after
|
|
54
|
+
every required write succeeded. Host draft via `draft` / `onDraftChange` (bound to the person, never shown to another
|
|
55
|
+
account); as in `ProfileComponent`, fields the person edited win over later server values for the same person, so
|
|
56
|
+
drop the draft once the step completes. `formId` hands the submit to the shell; `onBusyChange` reports saving.
|
|
57
|
+
|
|
58
|
+
**Continuation.** `LoginContent` and `SignUpContent` take a `continuation`: a same-origin path such as `/setup`. Anything
|
|
59
|
+
else (absolute, protocol-relative, backslash) falls back to `/`. It is also the Google/Microsoft callback URL, so render
|
|
60
|
+
`LoginContent` on that route: it shows a cancelled provider sign-in (`?error=`) with the choice again and handles a
|
|
61
|
+
person who arrives signed in. The emailed confirmation link carries no continuation: render `SignupConfirmContent` on
|
|
62
|
+
your app's `/signup/confirm` route inside the setup and follow it with `LoginContent` and your continuation, which also
|
|
63
|
+
works when the link is opened in a fresh session. An anonymous setup route needs `addPublicPath('/setup')` before the
|
|
64
|
+
`AuthProvider` mounts.
|
|
65
|
+
Passwords, tokens and access codes never leave the components; host drafts contain names and choices only.
|
|
66
|
+
|
|
67
|
+
**Terms of use (requires `django-core-micha` >= 3.16.0).** `ProfileStepContent` with `termsEnabled` shows the combined
|
|
68
|
+
statement "Ich akzeptiere die Nutzungsbedingungen und die Datenschutzerklärung." and records the acceptance through
|
|
69
|
+
`createTermsApi()` (`getAcceptance()`, `accept(version)`; default prefix `/api/terms/`, pass `{ apiBase }` for another
|
|
70
|
+
mount, created once at module level and passed as `termsApi`). The statement is pre-checked only when the server reports
|
|
71
|
+
the current version as accepted and privacy as accepted. A changed version (409 `version_mismatch`) keeps the step open
|
|
72
|
+
with the current document. Without `termsEnabled` nothing requests the terms API.
|
|
73
|
+
|
|
74
|
+
**Contextual checkout (requires `django-core-micha` >= 3.16.0).** `createBillingApi()` keeps `startCheckout(planKey)`
|
|
75
|
+
unchanged. `startCheckout(planKey, { context, idempotencyKey })` sends only `plan_key`, `context` and `idempotency_key`
|
|
76
|
+
(no return URL is ever sent). Create the key with `createCheckoutIdempotencyKey()` once per deliberate pay click and
|
|
77
|
+
reuse it when retrying that click; a new key is a new attempt. On return, read `checkout_attempt` from the URL and call
|
|
78
|
+
`resolveCheckoutAttempt(reference)` (`{ url, attempt }`, `attempt.status` `open | processing | paid | failed | expired`).
|
|
79
|
+
Access still comes only from `getMe()`. Nothing retries automatically. To give `PlanPicker` a context, pass an override:
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
const base = createBillingApi();
|
|
83
|
+
const setupBillingApi = createBillingApi({
|
|
84
|
+
startCheckout: (planKey) => base.startCheckout(planKey, { context: 'setup', idempotencyKey: currentAttemptKey() }),
|
|
85
|
+
});
|
|
86
|
+
<PlanPicker api={setupBillingApi} plans={plans} />;
|
|
87
|
+
```
|
|
88
|
+
|
|
33
89
|
## Consumer integration check
|
|
34
90
|
|
|
35
91
|
```js
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import apiClient from './apiClient';
|
|
2
|
+
/** Create the opt-in DCM-AUTH-12 terms acceptance client (requires DCM >= 3.16.0). */
|
|
3
|
+
export function createTermsApi(overrides = {}, { apiBase = '/api/terms/' } = {}) {
|
|
4
|
+
const root = `${String(apiBase).replace(/\/$/, '')}/`;
|
|
5
|
+
const data = (request) => request.then((response) => response.data);
|
|
6
|
+
const defaults = {
|
|
7
|
+
getAcceptance: () => data(apiClient.get(root)),
|
|
8
|
+
accept: (version) => data(apiClient.post(root, { version, accept: true })),
|
|
9
|
+
};
|
|
10
|
+
return Object.assign(Object.assign({}, defaults), overrides);
|
|
11
|
+
}
|
|
12
|
+
export const defaultTermsApi = createTermsApi();
|
package/dist/billing/api.js
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import apiClient from '../auth/apiClient';
|
|
2
2
|
import { billingApiUrls } from './wire';
|
|
3
|
+
/**
|
|
4
|
+
* Billing HTTP client. `startCheckout(planKey)` keeps the legacy request shape.
|
|
5
|
+
* Contextual checkout and `resolveCheckoutAttempt` require django-core-micha >= 3.16.0;
|
|
6
|
+
* contextual calls require `{ context, idempotencyKey }` and never accept redirect URLs.
|
|
7
|
+
*/
|
|
3
8
|
export function createBillingApi(overrides = {}, { apiBase = '/api/billing/' } = {}) {
|
|
4
9
|
const urls = billingApiUrls(apiBase);
|
|
5
10
|
const data = (request) => request.then((response) => response.data);
|
|
11
|
+
const validToken = (value) => typeof value === 'string' && /^[A-Za-z0-9_-]{16,64}$/.test(value);
|
|
6
12
|
const defaults = {
|
|
7
13
|
getMe: () => data(apiClient.get(urls.me)),
|
|
8
|
-
startCheckout: (planKey) =>
|
|
14
|
+
startCheckout: (planKey, options) => {
|
|
15
|
+
if ((options === null || options === void 0 ? void 0 : options.context) === undefined || (options === null || options === void 0 ? void 0 : options.context) === null)
|
|
16
|
+
return data(apiClient.post(urls.checkout, { plan_key: planKey }));
|
|
17
|
+
if (!validToken(options === null || options === void 0 ? void 0 : options.idempotencyKey))
|
|
18
|
+
return Promise.reject(new TypeError('A valid idempotencyKey is required for contextual checkout.'));
|
|
19
|
+
return data(apiClient.post(urls.checkout, { plan_key: planKey, context: options.context, idempotency_key: options.idempotencyKey }));
|
|
20
|
+
},
|
|
21
|
+
resolveCheckoutAttempt: (reference) => {
|
|
22
|
+
if (!validToken(reference))
|
|
23
|
+
return Promise.reject(new TypeError('A valid checkout attempt reference is required.'));
|
|
24
|
+
return data(apiClient.get(urls.checkoutAttempt(reference)));
|
|
25
|
+
},
|
|
9
26
|
openPortal: () => data(apiClient.post(urls.portal)),
|
|
10
27
|
listSeats: () => data(apiClient.get(urls.seats)),
|
|
11
28
|
addSeat: ({ userId, email } = {}) => data(apiClient.post(urls.seats, userId !== undefined ? { user_id: userId } : { email })),
|
|
@@ -29,4 +46,15 @@ export function createBillingApi(overrides = {}, { apiBase = '/api/billing/' } =
|
|
|
29
46
|
};
|
|
30
47
|
return Object.assign(Object.assign({}, defaults), overrides);
|
|
31
48
|
}
|
|
49
|
+
export function createCheckoutIdempotencyKey() {
|
|
50
|
+
const cryptoApi = globalThis.crypto;
|
|
51
|
+
if (typeof (cryptoApi === null || cryptoApi === void 0 ? void 0 : cryptoApi.randomUUID) === 'function')
|
|
52
|
+
return cryptoApi.randomUUID().replace(/-/g, '_');
|
|
53
|
+
if (typeof (cryptoApi === null || cryptoApi === void 0 ? void 0 : cryptoApi.getRandomValues) === 'function') {
|
|
54
|
+
const bytes = new Uint8Array(24);
|
|
55
|
+
cryptoApi.getRandomValues(bytes);
|
|
56
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
57
|
+
}
|
|
58
|
+
throw new Error('A cryptographic random source is required to create a checkout key.');
|
|
59
|
+
}
|
|
32
60
|
export const defaultBillingApi = createBillingApi();
|
package/dist/billing/wire.js
CHANGED
|
@@ -9,6 +9,7 @@ export const billingApiUrls = (base = '/api/billing/') => {
|
|
|
9
9
|
return {
|
|
10
10
|
me: root + 'me/',
|
|
11
11
|
checkout: root + 'checkout/',
|
|
12
|
+
checkoutAttempt: (reference) => root + `checkout/attempts/${encodeURIComponent(reference)}/`,
|
|
12
13
|
portal: root + 'portal/',
|
|
13
14
|
seats: root + 'team/seats/',
|
|
14
15
|
withdrawals: root + 'withdrawal/',
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useNavigate, useLocation } from 'react-router-dom';
|
|
4
|
+
import { Box, Alert } from '@mui/material';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { NarrowPage } from '../layout/PageLayout';
|
|
7
|
+
import { AuthContext } from '../auth/AuthContext';
|
|
8
|
+
import { fetchRecoverySessionToken, loginWithPassword, loginWithRecoveryPassword, } from '../auth/authApi';
|
|
9
|
+
import { loginWithPasskey, startSocialLogin } from '../utils/authService';
|
|
10
|
+
import { LoginForm } from './LoginForm';
|
|
11
|
+
import { MfaLoginComponent } from './MfaLoginComponent';
|
|
12
|
+
import { resolveErrorText } from '../utils/resolveErrorText';
|
|
13
|
+
import { RECOVERY_SECURITY_TARGET, resolveContinuationTarget, sanitizeContinuation, } from '../utils/continuation';
|
|
14
|
+
import { profileIdentity } from '../utils/profileDraft';
|
|
15
|
+
export const LOGIN_PAGE_ALERT_SX = { mb: 2 };
|
|
16
|
+
const PROVIDER_NAMES = { google: 'Google', microsoft: 'Microsoft' };
|
|
17
|
+
/**
|
|
18
|
+
* The login controller shared by LoginPage (`pageMode`) and LoginContent: password,
|
|
19
|
+
* passkey, MFA, recovery and provider sign-in, with one redirect precedence
|
|
20
|
+
* (`resolveContinuationTarget`). Page mode keeps the page's `?next=` source, its
|
|
21
|
+
* framing, the S164 recovery hand-off and its navigations. Embedded mode takes the
|
|
22
|
+
* continuation from a prop and never touches the URL recovery sentinel.
|
|
23
|
+
*/
|
|
24
|
+
export function LoginFlow({ pageMode = false, continuation, onSuccess, onForgotPassword, onSignUp, showProviders = true, }) {
|
|
25
|
+
const navigate = useNavigate();
|
|
26
|
+
const location = useLocation();
|
|
27
|
+
const { user, loading, login, authMethods } = useContext(AuthContext) || {};
|
|
28
|
+
const { t, i18n } = useTranslation();
|
|
29
|
+
const [step, setStep] = useState('credentials'); // 'credentials' | 'mfa'
|
|
30
|
+
const [submitting, setSubmitting] = useState(false);
|
|
31
|
+
const [errorKey, setErrorKey] = useState(null);
|
|
32
|
+
const [mfaState, setMfaState] = useState(null); // { availableTypes: [...], identifier }
|
|
33
|
+
// S164: token never travels through the URL/fragment anymore. It is held
|
|
34
|
+
// in component state only, fetched from the server-side session handoff
|
|
35
|
+
// endpoint when the redirect lands the SPA here with `#recovery=ok`.
|
|
36
|
+
const [recoveryToken, setRecoveryToken] = useState(null);
|
|
37
|
+
const [recoveryFetching, setRecoveryFetching] = useState(false);
|
|
38
|
+
const [providerTransition, setProviderTransition] = useState('');
|
|
39
|
+
// Embedded mode reports a signed-in person to the host once per identity, so a
|
|
40
|
+
// later refresh of the same user does not re-run the host's continuation.
|
|
41
|
+
const handledIdentity = useRef(undefined);
|
|
42
|
+
const params = new URLSearchParams(location.search);
|
|
43
|
+
const hashParams = new URLSearchParams(String(location.hash || '').startsWith('#') ? String(location.hash).slice(1) : String(location.hash || ''));
|
|
44
|
+
// After S164 the hash carries only a status sentinel: `ok`, `invalid`, or
|
|
45
|
+
// `expired`. We also accept the same key from query params as a defensive
|
|
46
|
+
// fallback for proxies that strip fragments. Page mode only: the recovery
|
|
47
|
+
// link always targets the login page.
|
|
48
|
+
const recoveryStatus = pageMode
|
|
49
|
+
? String(hashParams.get('recovery') || params.get('recovery') || '').toLowerCase()
|
|
50
|
+
: '';
|
|
51
|
+
// Backward-compatible fallback for legacy links using query parameters.
|
|
52
|
+
const recoveryEmail = pageMode ? hashParams.get('email') || params.get('email') || '' : '';
|
|
53
|
+
const requestedNext = pageMode ? params.get('next') : continuation;
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const socialError = params.get('error') || params.get('social');
|
|
56
|
+
if (socialError) {
|
|
57
|
+
setErrorKey(t('Auth.SOCIAL_LOGIN_FAILED'));
|
|
58
|
+
}
|
|
59
|
+
}, [location.search]);
|
|
60
|
+
// S164 handoff: on `#recovery=ok`, pull the plaintext token out of the
|
|
61
|
+
// server-side session (one-shot). On `invalid`/`expired`, or on any
|
|
62
|
+
// other non-empty value (legacy pre-S164 email links that carried the
|
|
63
|
+
// token directly in the hash), surface an invalid-link error so the
|
|
64
|
+
// user gets feedback instead of a silent login screen.
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
var _a;
|
|
67
|
+
if (!recoveryStatus) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Strip the `recovery=…` sentinel from BOTH hash and query string so a
|
|
71
|
+
// bookmark or page refresh does not re-trigger this effect against an
|
|
72
|
+
// already-popped session entry (which would render a confusing
|
|
73
|
+
// "invalid" error to a user who is mid-login).
|
|
74
|
+
//
|
|
75
|
+
// We use `history.replaceState` rather than `navigate(..., {replace})`
|
|
76
|
+
// intentionally: react-router's `navigate` would trigger an immediate
|
|
77
|
+
// re-render with an updated `useLocation()`, which would cause this
|
|
78
|
+
// effect's cleanup to set `cancelled=true` and discard the in-flight
|
|
79
|
+
// recovery-token fetch result. `replaceState` only mutates the browser
|
|
80
|
+
// URL bar; `useLocation()` stays at `recovery=ok` for this render, the
|
|
81
|
+
// fetch resolves, and `recoveryToken` gets set normally. The trade-off
|
|
82
|
+
// is that `useLocation().hash` is stale for the page lifetime — fine
|
|
83
|
+
// because nothing else in this component reads it.
|
|
84
|
+
if (typeof window !== 'undefined' && ((_a = window.history) === null || _a === void 0 ? void 0 : _a.replaceState)) {
|
|
85
|
+
const cleanParams = new URLSearchParams(window.location.search);
|
|
86
|
+
cleanParams.delete('recovery');
|
|
87
|
+
const cleanSearch = cleanParams.toString();
|
|
88
|
+
const cleanUrl = window.location.pathname + (cleanSearch ? `?${cleanSearch}` : '');
|
|
89
|
+
window.history.replaceState(null, '', cleanUrl);
|
|
90
|
+
}
|
|
91
|
+
if (recoveryStatus === 'expired') {
|
|
92
|
+
setErrorKey(t('Auth.RECOVERY_TOKEN_EXPIRED'));
|
|
93
|
+
setRecoveryToken(null);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (recoveryStatus !== 'ok') {
|
|
97
|
+
// Catches `invalid` and any unknown value (including legacy email
|
|
98
|
+
// links that carried the plaintext token before S164).
|
|
99
|
+
setErrorKey(t('Auth.RECOVERY_TOKEN_INVALID'));
|
|
100
|
+
setRecoveryToken(null);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let cancelled = false;
|
|
104
|
+
setRecoveryFetching(true);
|
|
105
|
+
fetchRecoverySessionToken()
|
|
106
|
+
.then((token) => {
|
|
107
|
+
if (cancelled)
|
|
108
|
+
return;
|
|
109
|
+
if (!token) {
|
|
110
|
+
// Session entry missing or already consumed — treat as invalid.
|
|
111
|
+
setErrorKey(t('Auth.RECOVERY_TOKEN_INVALID'));
|
|
112
|
+
setRecoveryToken(null);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
setRecoveryToken(token);
|
|
116
|
+
})
|
|
117
|
+
.catch((err) => {
|
|
118
|
+
if (cancelled)
|
|
119
|
+
return;
|
|
120
|
+
setErrorKey(resolveErrorText(i18n, err, 'Auth.RECOVERY_TOKEN_INVALID'));
|
|
121
|
+
setRecoveryToken(null);
|
|
122
|
+
})
|
|
123
|
+
.finally(() => {
|
|
124
|
+
if (!cancelled) {
|
|
125
|
+
setRecoveryFetching(false);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return () => {
|
|
129
|
+
cancelled = true;
|
|
130
|
+
};
|
|
131
|
+
}, [recoveryStatus]);
|
|
132
|
+
// A person who is already signed in when this renders (for example after a
|
|
133
|
+
// provider callback) goes through the same precedence as a fresh sign-in.
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
var _a;
|
|
136
|
+
if (loading || !user)
|
|
137
|
+
return;
|
|
138
|
+
const target = resolveContinuationTarget(requestedNext, user);
|
|
139
|
+
if (pageMode) {
|
|
140
|
+
navigate(target, { replace: true });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const identity = profileIdentity(user);
|
|
144
|
+
if (handledIdentity.current === identity)
|
|
145
|
+
return;
|
|
146
|
+
handledIdentity.current = identity;
|
|
147
|
+
if (((_a = user.security_state) === null || _a === void 0 ? void 0 : _a.requires_additional_security) === true) {
|
|
148
|
+
navigate(target, { replace: true });
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess({ user, target });
|
|
152
|
+
}
|
|
153
|
+
}, [loading, user, navigate, requestedNext, pageMode]);
|
|
154
|
+
// --- Helper: Central Success Logic ---
|
|
155
|
+
// A forced or required-security target is navigated here, never handed back
|
|
156
|
+
// to the host, so an embedded continuation cannot skip it.
|
|
157
|
+
const handleLoginSuccess = (currentUser, forcedTarget) => {
|
|
158
|
+
var _a;
|
|
159
|
+
login(currentUser); // Update Context
|
|
160
|
+
const target = resolveContinuationTarget(requestedNext, currentUser, forcedTarget);
|
|
161
|
+
if (pageMode) {
|
|
162
|
+
navigate(target);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
handledIdentity.current = profileIdentity(currentUser);
|
|
166
|
+
if (forcedTarget || ((_a = currentUser === null || currentUser === void 0 ? void 0 : currentUser.security_state) === null || _a === void 0 ? void 0 : _a.requires_additional_security) === true) {
|
|
167
|
+
navigate(target);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess({ user: currentUser, target });
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
// --- Handlers ---
|
|
174
|
+
const handleSubmitCredentials = async ({ identifier, password }) => {
|
|
175
|
+
setErrorKey(null);
|
|
176
|
+
setSubmitting(true);
|
|
177
|
+
try {
|
|
178
|
+
// A) Recovery Flow
|
|
179
|
+
if (recoveryToken) {
|
|
180
|
+
const result = await loginWithRecoveryPassword(identifier, password, recoveryToken);
|
|
181
|
+
handleLoginSuccess(result.user, RECOVERY_SECURITY_TARGET);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// B) Standard Password Login
|
|
185
|
+
const result = await loginWithPassword(identifier, password);
|
|
186
|
+
if (result.needsMfa) {
|
|
187
|
+
setMfaState({
|
|
188
|
+
availableTypes: result.availableTypes || [],
|
|
189
|
+
identifier,
|
|
190
|
+
});
|
|
191
|
+
setStep('mfa');
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
handleLoginSuccess(result.user);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
setErrorKey(resolveErrorText(i18n, err, 'Auth.LOGIN_FAILED'));
|
|
199
|
+
}
|
|
200
|
+
finally {
|
|
201
|
+
setSubmitting(false);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const handlePasskeyLoginInitial = async () => {
|
|
205
|
+
setErrorKey(null);
|
|
206
|
+
setSubmitting(true);
|
|
207
|
+
try {
|
|
208
|
+
// Service handles browser interaction + API calls
|
|
209
|
+
const passkeyUser = await loginWithPasskey();
|
|
210
|
+
handleLoginSuccess(passkeyUser);
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
if (err.code !== 'Auth.PASSKEY_CANCELLED') {
|
|
214
|
+
setErrorKey(resolveErrorText(i18n, err, 'Auth.PASSKEY_FAILED'));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
finally {
|
|
218
|
+
setSubmitting(false);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const handleMfaSuccess = ({ user: mfaUser, method }) => {
|
|
222
|
+
// MFA component returns the user object after verifying the code
|
|
223
|
+
handleLoginSuccess(mfaUser, method === 'recovery_code' ? RECOVERY_SECURITY_TARGET : undefined);
|
|
224
|
+
};
|
|
225
|
+
const handleMfaCancel = () => {
|
|
226
|
+
setStep('credentials');
|
|
227
|
+
setMfaState(null);
|
|
228
|
+
setErrorKey(null);
|
|
229
|
+
};
|
|
230
|
+
// Embedded provider entry: the validated continuation becomes the callback URL
|
|
231
|
+
// (no continuation -> `startSocialLogin`'s own `/login` default). The page keeps
|
|
232
|
+
// its existing call unchanged.
|
|
233
|
+
const handleProviderLogin = async (provider) => {
|
|
234
|
+
setErrorKey(null);
|
|
235
|
+
setProviderTransition(provider);
|
|
236
|
+
const callbackUrl = sanitizeContinuation(continuation);
|
|
237
|
+
try {
|
|
238
|
+
await startSocialLogin(provider, callbackUrl ? { callbackUrl } : {});
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
setProviderTransition('');
|
|
242
|
+
setErrorKey(resolveErrorText(i18n, err, 'Auth.SOCIAL_LOGIN_FAILED'));
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const socialProviders = Array.isArray(authMethods === null || authMethods === void 0 ? void 0 : authMethods.social_providers)
|
|
246
|
+
? authMethods.social_providers
|
|
247
|
+
: [];
|
|
248
|
+
const passwordLoginEnabled = Boolean(authMethods === null || authMethods === void 0 ? void 0 : authMethods.password_login) || Boolean(recoveryToken);
|
|
249
|
+
const socialLoginEnabled = Boolean(authMethods === null || authMethods === void 0 ? void 0 : authMethods.social_login) && socialProviders.length > 0
|
|
250
|
+
&& (pageMode || showProviders);
|
|
251
|
+
const passkeyLoginEnabled = Boolean(authMethods === null || authMethods === void 0 ? void 0 : authMethods.passkey_login);
|
|
252
|
+
const signupModes = Array.isArray(authMethods === null || authMethods === void 0 ? void 0 : authMethods.signup_modes)
|
|
253
|
+
? authMethods.signup_modes.filter(Boolean)
|
|
254
|
+
: [];
|
|
255
|
+
const signupEnabled = signupModes.length > 0 || Boolean(authMethods === null || authMethods === void 0 ? void 0 : authMethods.signup);
|
|
256
|
+
const passwordResetEnabled = Boolean(authMethods === null || authMethods === void 0 ? void 0 : authMethods.password_reset);
|
|
257
|
+
const twoFactorRequired = Boolean(authMethods === null || authMethods === void 0 ? void 0 : authMethods.two_factor_required)
|
|
258
|
+
|| Number((authMethods === null || authMethods === void 0 ? void 0 : authMethods.required_auth_factor_count) || 1) >= 2;
|
|
259
|
+
const pageSignUp = signupEnabled ? () => navigate('/signup') : null;
|
|
260
|
+
const pageForgotPassword = passwordResetEnabled ? () => navigate('/reset-request-password') : null;
|
|
261
|
+
// --- Render ---
|
|
262
|
+
const content = (_jsxs(_Fragment, { children: [errorKey && (_jsx(Alert, { severity: "error", sx: LOGIN_PAGE_ALERT_SX, children: errorKey })), !pageMode && providerTransition && (_jsx(Alert, { severity: "info", sx: LOGIN_PAGE_ALERT_SX, children: t('Auth.PROVIDER_TRANSITION', { provider: PROVIDER_NAMES[providerTransition] || providerTransition }) })), recoveryFetching && !errorKey && (_jsx(Alert, { severity: "info", sx: LOGIN_PAGE_ALERT_SX, children: t('Auth.RECOVERY_LINK_VALIDATING', 'Validating recovery link…') })), recoveryToken && !errorKey && (_jsx(Alert, { severity: "info", sx: LOGIN_PAGE_ALERT_SX, children: t('Auth.RECOVERY_LOGIN_WARNING', 'Recovery link validated. Please enter your password.') })), pageMode && twoFactorRequired && !recoveryToken && !recoveryFetching && (_jsx(Alert, { severity: "info", sx: LOGIN_PAGE_ALERT_SX, children: t('Auth.TWO_FACTOR_REQUIRED_HINT', 'This app requires two authentication factors for full access.') })), step === 'credentials' && (_jsx(LoginForm, { onSubmit: passwordLoginEnabled ? handleSubmitCredentials : null, onForgotPassword: pageMode ? pageForgotPassword : (onForgotPassword || null), onSocialLogin: socialLoginEnabled
|
|
263
|
+
? (pageMode ? (provider) => startSocialLogin(provider) : handleProviderLogin)
|
|
264
|
+
: null, socialProviders: socialProviders, onPasskeyLogin: passkeyLoginEnabled ? handlePasskeyLoginInitial : null, onSignUp: pageMode ? pageSignUp : (onSignUp || null),
|
|
265
|
+
// Block submit while the handoff is in flight so the user does not
|
|
266
|
+
// race the recovery-token fetch with a normal password POST.
|
|
267
|
+
disabled: submitting || recoveryFetching || Boolean(providerTransition), initialIdentifier: recoveryEmail })), step === 'mfa' && mfaState && (_jsx(Box, { children: _jsx(MfaLoginComponent, { availableTypes: mfaState.availableTypes, identifier: mfaState.identifier, onSuccess: handleMfaSuccess, onCancel: handleMfaCancel }) }))] }));
|
|
268
|
+
if (!pageMode) {
|
|
269
|
+
return _jsx(Box, { sx: { width: '100%' }, children: content });
|
|
270
|
+
}
|
|
271
|
+
return (_jsxs(NarrowPage, { title: t('Auth.PAGE_LOGIN_TITLE'), subtitle: t('Auth.PAGE_LOGIN_SUBTITLE'), children: [_jsx("title", { children: `${t('App.NAME')} – ${t('Auth.PAGE_LOGIN_TITLE')}` }), content] }));
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Embeddable login for a host flow such as a setup wizard (requires no new DCM
|
|
275
|
+
* version). Same controller as LoginPage, rendered without page framing, with the
|
|
276
|
+
* MFA step inline.
|
|
277
|
+
*
|
|
278
|
+
* Props:
|
|
279
|
+
* - `continuation`: same-origin path to return to (validated; anything else falls
|
|
280
|
+
* back to `/`). Also used as the provider callback URL.
|
|
281
|
+
* - `onSuccess({ user, target })`: called once per signed-in person, after a
|
|
282
|
+
* password, passkey or MFA sign-in, or when the person is already signed in on
|
|
283
|
+
* arrival (provider callback). Not called when recovery or required additional
|
|
284
|
+
* security applies: the component then navigates to the security page itself.
|
|
285
|
+
* - `onSignUp`, `onForgotPassword`: optional handlers; the buttons are hidden
|
|
286
|
+
* without them.
|
|
287
|
+
* - `showProviders` (default true): Google/Microsoft entry when the app enables it.
|
|
288
|
+
* A provider callback that returns with `?error=` or `?social=` shows the existing
|
|
289
|
+
* failure message and the provider choice again.
|
|
290
|
+
*/
|
|
291
|
+
export function LoginContent({ continuation, onSuccess, onSignUp, onForgotPassword, showProviders = true }) {
|
|
292
|
+
return (_jsx(LoginFlow, { continuation: continuation, onSuccess: onSuccess, onSignUp: onSignUp, onForgotPassword: onForgotPassword, showProviders: showProviders }));
|
|
293
|
+
}
|
|
@@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
7
7
|
import { AuthContext } from '../auth/AuthContext';
|
|
8
8
|
import { fetchCookieStatement, fetchPrivacyStatement } from '../auth/authApi';
|
|
9
9
|
import { resolveErrorText } from '../utils/resolveErrorText';
|
|
10
|
+
import { refreshProfileDraft } from '../utils/profileDraft';
|
|
10
11
|
export function ProfileComponent({ onSubmit, submitText, showName = true, showPrivacy = true, showCookies = true, showStatements = true, privacyStatementText = null, cookieStatementText = null, }) {
|
|
11
12
|
const { t, i18n } = useTranslation();
|
|
12
13
|
// WICHTIG: Wir holen den User direkt aus dem globalen State
|
|
@@ -30,36 +31,17 @@ export function ProfileComponent({ onSubmit, submitText, showName = true, showPr
|
|
|
30
31
|
const [loadingCookieStatement, setLoadingCookieStatement] = useState(false);
|
|
31
32
|
// Refresh server values for untouched fields, while keeping edits for this identity.
|
|
32
33
|
useEffect(() => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!editedFields.current.has('firstName'))
|
|
45
|
-
setFirstName((_f = user.first_name) !== null && _f !== void 0 ? _f : '');
|
|
46
|
-
if (!editedFields.current.has('lastName'))
|
|
47
|
-
setLastName((_g = user.last_name) !== null && _g !== void 0 ? _g : '');
|
|
48
|
-
if (!editedFields.current.has('acceptedPrivacy')) {
|
|
49
|
-
setAcceptedPrivacy(Boolean(user.accepted_privacy_statement));
|
|
50
|
-
}
|
|
51
|
-
if (!editedFields.current.has('acceptedCookies')) {
|
|
52
|
-
setAcceptedCookies(Boolean(user.accepted_convenience_cookies));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
setUsername('');
|
|
57
|
-
setEmail('');
|
|
58
|
-
setFirstName('');
|
|
59
|
-
setLastName('');
|
|
60
|
-
setAcceptedPrivacy(false);
|
|
61
|
-
setAcceptedCookies(false);
|
|
62
|
-
}
|
|
34
|
+
const refreshed = refreshProfileDraft(user, previousUserIdentity.current, editedFields.current, {
|
|
35
|
+
firstName, lastName, acceptedPrivacy, acceptedCookies,
|
|
36
|
+
});
|
|
37
|
+
previousUserIdentity.current = refreshed.identity;
|
|
38
|
+
editedFields.current = refreshed.editedFields;
|
|
39
|
+
setUsername(refreshed.values.username);
|
|
40
|
+
setEmail(refreshed.values.email);
|
|
41
|
+
setFirstName(refreshed.values.firstName);
|
|
42
|
+
setLastName(refreshed.values.lastName);
|
|
43
|
+
setAcceptedPrivacy(refreshed.values.acceptedPrivacy);
|
|
44
|
+
setAcceptedCookies(refreshed.values.acceptedCookies);
|
|
63
45
|
}, [user]);
|
|
64
46
|
useEffect(() => {
|
|
65
47
|
if (privacyStatementText !== null && privacyStatementText !== undefined) {
|