@ory/elements-react 1.0.0-next.13 → 1.0.0-next.15

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/dist/index.js CHANGED
@@ -85,6 +85,71 @@ function OryComponentProvider({
85
85
  }
86
86
  );
87
87
  }
88
+ function isChoosingMethod(uiNodes) {
89
+ return uiNodes.some(
90
+ (node) => "name" in node.attributes && node.attributes.name === "screen" && "value" in node.attributes && node.attributes.value === "previous"
91
+ ) || uiNodes.some(
92
+ (node) => node.group === clientFetch.UiNodeGroupEnum.IdentifierFirst && "name" in node.attributes && node.attributes.name === "identifier" && node.attributes.type === "hidden"
93
+ );
94
+ }
95
+ function filterZeroStepGroups(nodes) {
96
+ return nodes.filter((node) => node.group !== clientFetch.UiNodeGroupEnum.Oidc);
97
+ }
98
+ function getFinalNodes(uniqueGroups, selectedGroup) {
99
+ var _a, _b, _c;
100
+ const selectedNodes = selectedGroup ? (_a = uniqueGroups[selectedGroup]) != null ? _a : [] : [];
101
+ return [
102
+ ...(_b = uniqueGroups == null ? void 0 : uniqueGroups.identifier_first) != null ? _b : [],
103
+ ...(_c = uniqueGroups == null ? void 0 : uniqueGroups.default) != null ? _c : []
104
+ ].flat().filter(
105
+ (node) => "type" in node.attributes && node.attributes.type === "hidden"
106
+ ).concat(selectedNodes);
107
+ }
108
+
109
+ // src/context/form-state.ts
110
+ function parseStateFromFlow(flow) {
111
+ switch (flow.flowType) {
112
+ case clientFetch.FlowType.Registration:
113
+ case clientFetch.FlowType.Login:
114
+ if (flow.flow.active == "link_recovery") {
115
+ return { current: "method_active", method: "link" };
116
+ } else if (flow.flow.active == "code_recovery") {
117
+ return { current: "method_active", method: "code" };
118
+ } else if (isChoosingMethod(flow.flow.ui.nodes)) {
119
+ return { current: "select_method" };
120
+ } else if (flow.flow.active) {
121
+ return { current: "method_active", method: flow.flow.active };
122
+ }
123
+ return { current: "provide_identifier" };
124
+ case clientFetch.FlowType.Recovery:
125
+ case clientFetch.FlowType.Verification:
126
+ if (flow.flow.active === "code" || flow.flow.active === "link") {
127
+ if (flow.flow.state === "choose_method") {
128
+ return { current: "provide_identifier" };
129
+ }
130
+ return { current: "method_active", method: flow.flow.active };
131
+ }
132
+ break;
133
+ case clientFetch.FlowType.Settings:
134
+ return { current: "settings" };
135
+ }
136
+ console.warn(
137
+ `[Ory/Elements React] Encountered an unknown form state on ${flow.flowType} flow with ID ${flow.flow.id}`
138
+ );
139
+ throw new Error("Unknown form state");
140
+ }
141
+ function formStateReducer(state, action) {
142
+ switch (action.type) {
143
+ case "action_flow_update":
144
+ return parseStateFromFlow(action.flow);
145
+ case "action_select_method":
146
+ return { current: "method_active", method: action.method };
147
+ }
148
+ return state;
149
+ }
150
+ function useFormStateReducer(flow) {
151
+ return react.useReducer(formStateReducer, parseStateFromFlow(flow));
152
+ }
88
153
  function useOryFlow() {
89
154
  const ctx = react.useContext(OryFlowContext);
90
155
  if (!ctx) {
@@ -98,19 +163,21 @@ function OryFlowProvider({
98
163
  ...container
99
164
  }) {
100
165
  const [flowContainer, setFlowContainer] = react.useState(container);
166
+ const [formState, dispatchFormState] = useFormStateReducer(container);
101
167
  return /* @__PURE__ */ jsxRuntime.jsx(
102
168
  OryFlowContext.Provider,
103
169
  {
104
170
  value: {
105
171
  ...flowContainer,
106
- setFlowContainer: (updatedContainer) => {
107
- setFlowContainer(
108
- (container2) => ({
109
- ...container2,
110
- ...updatedContainer
111
- })
112
- );
113
- }
172
+ setFlowContainer: (flowContainer2) => {
173
+ setFlowContainer(flowContainer2);
174
+ dispatchFormState({
175
+ type: "action_flow_update",
176
+ flow: flowContainer2
177
+ });
178
+ },
179
+ formState,
180
+ dispatchFormState
114
181
  },
115
182
  children
116
183
  }
@@ -359,7 +426,8 @@ var en_default = {
359
426
  "settings.webauthn.info": "Hardware Tokens are used for second-factor authentication or as first-factor with Passkeys",
360
427
  "settings.passkey.title": "Manage Passkeys",
361
428
  "settings.passkey.description": "Manage your passkey settings",
362
- "settings.passkey.info": "Manage your passkey settings"
429
+ "settings.passkey.info": "Manage your passkey settings",
430
+ "card.footer.select-another-method": "Select another method"
363
431
  };
364
432
 
365
433
  // src/locales/de.json
@@ -604,7 +672,8 @@ var de_default = {
604
672
  "settings.title-profile": "Profileinstellungen",
605
673
  "settings.title-totp": "Verwalten Sie die 2FA TOTP Authenticator-App",
606
674
  "settings.title-webauthn": "Hardware-Token verwalten",
607
- "settings.webauthn.info": "Hardware-Tokens werden f\xFCr die Zweitfaktor-Authentifizierung oder als Erstfaktor-Authentifizierung mit Passkeys verwendet"
675
+ "settings.webauthn.info": "Hardware-Tokens werden f\xFCr die Zweitfaktor-Authentifizierung oder als Erstfaktor-Authentifizierung mit Passkeys verwendet",
676
+ "card.footer.select-another-method": "Eine andere Methode verwenden"
608
677
  };
609
678
 
610
679
  // src/locales/es.json
@@ -849,7 +918,8 @@ var es_default = {
849
918
  "settings.title-profile": "",
850
919
  "settings.title-totp": "",
851
920
  "settings.title-webauthn": "",
852
- "settings.webauthn.info": ""
921
+ "settings.webauthn.info": "",
922
+ "card.footer.select-another-method": ""
853
923
  };
854
924
 
855
925
  // src/locales/fr.json
@@ -1094,7 +1164,8 @@ var fr_default = {
1094
1164
  "settings.title-webauthn": "",
1095
1165
  "settings.webauthn.description": "",
1096
1166
  "settings.webauthn.info": "",
1097
- "settings.webauthn.title": ""
1167
+ "settings.webauthn.title": "",
1168
+ "card.footer.select-another-method": ""
1098
1169
  };
1099
1170
 
1100
1171
  // src/locales/nl.json
@@ -1339,7 +1410,8 @@ var nl_default = {
1339
1410
  "settings.title-webauthn": "",
1340
1411
  "settings.webauthn.description": "",
1341
1412
  "settings.webauthn.info": "",
1342
- "settings.webauthn.title": ""
1413
+ "settings.webauthn.title": "",
1414
+ "card.footer.select-another-method": ""
1343
1415
  };
1344
1416
 
1345
1417
  // src/locales/pl.json
@@ -1584,7 +1656,8 @@ var pl_default = {
1584
1656
  "settings.title-webauthn": "",
1585
1657
  "settings.webauthn.description": "",
1586
1658
  "settings.webauthn.info": "",
1587
- "settings.webauthn.title": ""
1659
+ "settings.webauthn.title": "",
1660
+ "card.footer.select-another-method": ""
1588
1661
  };
1589
1662
 
1590
1663
  // src/locales/pt.json
@@ -1829,7 +1902,8 @@ var pt_default = {
1829
1902
  "settings.title-webauthn": "",
1830
1903
  "settings.webauthn.description": "",
1831
1904
  "settings.webauthn.info": "",
1832
- "settings.webauthn.title": ""
1905
+ "settings.webauthn.title": "",
1906
+ "card.footer.select-another-method": ""
1833
1907
  };
1834
1908
 
1835
1909
  // src/locales/sv.json
@@ -2074,7 +2148,8 @@ var sv_default = {
2074
2148
  "settings.title-webauthn": "Hantera maskinvarutokens",
2075
2149
  "settings.webauthn.description": "Hantera inst\xE4llningarna f\xF6r din maskinvarutoken",
2076
2150
  "settings.webauthn.info": "H\xE5rdvarutokens anv\xE4nds f\xF6r andrafaktorsautentisering eller som f\xF6rstafaktor med l\xF6senordsnycklar",
2077
- "settings.webauthn.title": "Hantera maskinvarutokens"
2151
+ "settings.webauthn.title": "Hantera maskinvarutokens",
2152
+ "card.footer.select-another-method": "V\xE4lj en annan metod"
2078
2153
  };
2079
2154
 
2080
2155
  // src/locales/index.ts
@@ -2133,6 +2208,246 @@ function OryCardHeader() {
2133
2208
  const { Card } = useComponents();
2134
2209
  return /* @__PURE__ */ jsxRuntime.jsx(Card.Header, {});
2135
2210
  }
2211
+ function frontendClient(sdkUrl, opts = {}) {
2212
+ const config = new clientFetch.Configuration({
2213
+ ...opts,
2214
+ basePath: sdkUrl,
2215
+ headers: {
2216
+ Accept: "application/json",
2217
+ ...opts.headers
2218
+ }
2219
+ });
2220
+ return new clientFetch.FrontendApi(config);
2221
+ }
2222
+
2223
+ // src/util/onSubmitLogin.ts
2224
+ async function onSubmitLogin({ config, flow }, {
2225
+ setFlowContainer,
2226
+ body,
2227
+ onRedirect
2228
+ }) {
2229
+ var _a;
2230
+ if (!config.sdk.url) {
2231
+ throw new Error(
2232
+ `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2233
+ );
2234
+ }
2235
+ await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateLoginFlowRaw({
2236
+ flow: flow.id,
2237
+ updateLoginFlowBody: body
2238
+ }).then(() => {
2239
+ var _a2;
2240
+ window.location.href = (_a2 = flow.return_to) != null ? _a2 : config.sdk.url + "/self-service/login/browser";
2241
+ }).catch(
2242
+ clientFetch.handleFlowError({
2243
+ onRestartFlow: () => {
2244
+ onRedirect(clientFetch.loginUrl(config), true);
2245
+ },
2246
+ onValidationError: (body2) => {
2247
+ setFlowContainer({
2248
+ config,
2249
+ flow: body2,
2250
+ flowType: clientFetch.FlowType.Login
2251
+ });
2252
+ },
2253
+ onRedirect
2254
+ })
2255
+ );
2256
+ }
2257
+ async function onSubmitRecovery({ config, flow }, {
2258
+ setFlowContainer,
2259
+ body,
2260
+ onRedirect
2261
+ }) {
2262
+ var _a;
2263
+ if (!config.sdk.url) {
2264
+ throw new Error(
2265
+ `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2266
+ );
2267
+ }
2268
+ await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateRecoveryFlowRaw({
2269
+ flow: flow.id,
2270
+ updateRecoveryFlowBody: body
2271
+ }).then(async (res) => {
2272
+ const flow2 = await res.value();
2273
+ const didContinueWith = clientFetch.handleContinueWith(flow2.continue_with, {
2274
+ onRedirect
2275
+ });
2276
+ if (didContinueWith) {
2277
+ return;
2278
+ }
2279
+ setFlowContainer({
2280
+ flow: flow2,
2281
+ flowType: clientFetch.FlowType.Recovery,
2282
+ config
2283
+ });
2284
+ }).catch(
2285
+ clientFetch.handleFlowError({
2286
+ onRestartFlow: () => {
2287
+ onRedirect(clientFetch.recoveryUrl(config), true);
2288
+ },
2289
+ onValidationError: (body2) => {
2290
+ setFlowContainer({
2291
+ flow: body2,
2292
+ flowType: clientFetch.FlowType.Recovery,
2293
+ config
2294
+ });
2295
+ },
2296
+ onRedirect
2297
+ })
2298
+ );
2299
+ }
2300
+ async function onSubmitRegistration({ config, flow }, {
2301
+ setFlowContainer,
2302
+ body,
2303
+ onRedirect
2304
+ }) {
2305
+ var _a;
2306
+ if (!config.sdk.url) {
2307
+ throw new Error(
2308
+ `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2309
+ );
2310
+ }
2311
+ const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
2312
+ await client.updateRegistrationFlowRaw({
2313
+ flow: flow.id,
2314
+ updateRegistrationFlowBody: body
2315
+ }).then(async (res) => {
2316
+ const body2 = await res.value();
2317
+ const didContinueWith = clientFetch.handleContinueWith(body2.continue_with, {
2318
+ onRedirect
2319
+ });
2320
+ if (didContinueWith) {
2321
+ return;
2322
+ }
2323
+ onRedirect(clientFetch.registrationUrl(config), true);
2324
+ }).catch(
2325
+ clientFetch.handleFlowError({
2326
+ onRestartFlow: () => {
2327
+ onRedirect(clientFetch.registrationUrl(config), true);
2328
+ },
2329
+ onValidationError: (body2) => {
2330
+ setFlowContainer({
2331
+ flow: body2,
2332
+ flowType: clientFetch.FlowType.Registration,
2333
+ config
2334
+ });
2335
+ },
2336
+ onRedirect
2337
+ })
2338
+ );
2339
+ }
2340
+ async function onSubmitSettings({ config, flow }, {
2341
+ setFlowContainer,
2342
+ body,
2343
+ onRedirect
2344
+ }) {
2345
+ var _a;
2346
+ if (!config.sdk.url) {
2347
+ throw new Error(
2348
+ `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2349
+ );
2350
+ }
2351
+ const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
2352
+ await client.updateSettingsFlowRaw({
2353
+ flow: flow.id,
2354
+ updateSettingsFlowBody: body
2355
+ }).then(async (res) => {
2356
+ const body2 = await res.value();
2357
+ const didContinueWith = clientFetch.handleContinueWith(body2.continue_with, {
2358
+ onRedirect
2359
+ });
2360
+ if (didContinueWith) {
2361
+ return;
2362
+ }
2363
+ onRedirect(clientFetch.settingsUrl(config), true);
2364
+ }).catch(
2365
+ clientFetch.handleFlowError({
2366
+ onRestartFlow: () => {
2367
+ onRedirect(clientFetch.settingsUrl(config), true);
2368
+ },
2369
+ onValidationError: (body2) => {
2370
+ setFlowContainer({
2371
+ flow: body2,
2372
+ flowType: clientFetch.FlowType.Settings,
2373
+ config
2374
+ });
2375
+ },
2376
+ onRedirect
2377
+ })
2378
+ ).catch((err) => {
2379
+ if (clientFetch.isResponseError(err)) {
2380
+ if (err.response.status === 401) {
2381
+ return onRedirect(
2382
+ clientFetch.loginUrl(config) + "?return_to=" + clientFetch.settingsUrl(config),
2383
+ true
2384
+ );
2385
+ }
2386
+ throw err;
2387
+ }
2388
+ });
2389
+ }
2390
+ async function onSubmitVerification({ config, flow }, {
2391
+ setFlowContainer,
2392
+ body,
2393
+ onRedirect
2394
+ }) {
2395
+ var _a;
2396
+ if (!config.sdk.url) {
2397
+ throw new Error(
2398
+ `Please supply your Ory Network SDK URL to the Ory Elements configuration.`
2399
+ );
2400
+ }
2401
+ await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateVerificationFlowRaw({
2402
+ flow: flow.id,
2403
+ updateVerificationFlowBody: body
2404
+ }).then(
2405
+ async (res) => setFlowContainer({
2406
+ flow: await res.value(),
2407
+ flowType: clientFetch.FlowType.Verification,
2408
+ config
2409
+ })
2410
+ ).catch(
2411
+ clientFetch.handleFlowError({
2412
+ onRestartFlow: () => {
2413
+ onRedirect(clientFetch.verificationUrl(config), true);
2414
+ },
2415
+ onValidationError: (body2) => {
2416
+ setFlowContainer({
2417
+ flow: body2,
2418
+ flowType: clientFetch.FlowType.Verification,
2419
+ config
2420
+ });
2421
+ },
2422
+ onRedirect
2423
+ })
2424
+ );
2425
+ }
2426
+ function computeDefaultValues(nodes) {
2427
+ return nodes.reduce((acc, node) => {
2428
+ const attrs = node.attributes;
2429
+ if (clientFetch.isUiNodeInputAttributes(attrs)) {
2430
+ if (attrs.name === "method" || attrs.type === "submit" || typeof attrs.value === "undefined")
2431
+ return acc;
2432
+ const unrolled = unrollTrait({
2433
+ name: attrs.name,
2434
+ value: attrs.value
2435
+ });
2436
+ Object.assign(acc, unrolled != null ? unrolled : { [attrs.name]: attrs.value });
2437
+ }
2438
+ return acc;
2439
+ }, {});
2440
+ }
2441
+ function unrollTrait(input, output = {}) {
2442
+ const keys = input.name.split(".");
2443
+ if (!keys.length) return void 0;
2444
+ let current = output;
2445
+ keys.forEach((key, index) => {
2446
+ if (!key) return;
2447
+ current = current[key] = index === keys.length - 1 ? input.value : current[key] || {};
2448
+ });
2449
+ return output;
2450
+ }
2136
2451
  function triggerToWindowCall(trigger) {
2137
2452
  if (!trigger) {
2138
2453
  return;
@@ -2143,10 +2458,10 @@ function triggerToWindowCall(trigger) {
2143
2458
  return;
2144
2459
  }
2145
2460
  let i = 0;
2146
- const ms = 250;
2461
+ const ms = 100;
2147
2462
  const interval = setInterval(() => {
2148
2463
  i++;
2149
- if (i > 20) {
2464
+ if (i > 100) {
2150
2465
  clearInterval(interval);
2151
2466
  throw new Error(
2152
2467
  "Unable to load Ory's WebAuthn script. Is it being blocked or otherwise failing to load? If you are running an old version of Ory Elements, please upgrade. For more information, please check your browser's developer console."
@@ -2187,6 +2502,9 @@ function useNodesGroups(nodes) {
2187
2502
  var _a;
2188
2503
  const groups2 = {};
2189
2504
  for (const node of nodes) {
2505
+ if (node.type === "script") {
2506
+ continue;
2507
+ }
2190
2508
  const groupNodes = (_a = groups2[node.group]) != null ? _a : [];
2191
2509
  groupNodes.push(node);
2192
2510
  groups2[node.group] = groupNodes;
@@ -2209,7 +2527,6 @@ var NodeInput = ({
2209
2527
  var _a;
2210
2528
  const { Node: Node2 } = useComponents();
2211
2529
  const { setValue } = reactHookForm.useFormContext();
2212
- const nodeType = attributes.type;
2213
2530
  const {
2214
2531
  onloadTrigger,
2215
2532
  onclickTrigger,
@@ -2245,14 +2562,15 @@ var NodeInput = ({
2245
2562
  };
2246
2563
  const isSocial = (attrs.name === "provider" || attrs.name === "link") && node.group === "oidc";
2247
2564
  const isPinCodeInput = attrs.name === "code" && node.group === "code" || attrs.name === "totp_code" && node.group === "totp";
2248
- const isResend = ((_a = node.meta.label) == null ? void 0 : _a.id) === 1070008;
2249
- switch (nodeType) {
2565
+ const isResendNode = ((_a = node.meta.label) == null ? void 0 : _a.id) === 1070008;
2566
+ const isScreenSelectionNode = "name" in node.attributes && node.attributes.name === "screen";
2567
+ switch (attributes.type) {
2250
2568
  case clientFetch.UiNodeInputAttributesTypeEnum.Submit:
2251
2569
  case clientFetch.UiNodeInputAttributesTypeEnum.Button:
2252
2570
  if (isSocial) {
2253
2571
  return /* @__PURE__ */ jsxRuntime.jsx(Node2.OidcButton, { attributes: attrs, node });
2254
2572
  }
2255
- if (isResend) {
2573
+ if (isResendNode || isScreenSelectionNode) {
2256
2574
  return null;
2257
2575
  }
2258
2576
  return /* @__PURE__ */ jsxRuntime.jsx(Node2.Button, { attributes: attrs, node, onClick: handleClick });
@@ -2364,235 +2682,11 @@ function OryFormSocialButtonsForm() {
2364
2682
  }
2365
2683
  return /* @__PURE__ */ jsxRuntime.jsx(OryForm, { children: /* @__PURE__ */ jsxRuntime.jsx(OryFormOidcButtons, {}) });
2366
2684
  }
2367
- function computeDefaultValues(nodes) {
2368
- return nodes.reduce((acc, node) => {
2369
- var _a;
2370
- if (clientFetch.isUiNodeInputAttributes(node.attributes)) {
2371
- if (node.attributes.name === "method") {
2372
- return acc;
2373
- }
2374
- if (node.attributes.type === "submit") {
2375
- return acc;
2376
- }
2377
- acc[node.attributes.name] = (_a = node.attributes.value) != null ? _a : "";
2378
- }
2379
- return acc;
2380
- }, {});
2381
- }
2382
- function frontendClient(sdkUrl, opts = {}) {
2383
- const config = new clientFetch.Configuration({
2384
- ...opts,
2385
- basePath: sdkUrl,
2386
- headers: {
2387
- Accept: "application/json",
2388
- ...opts.headers
2389
- }
2390
- });
2391
- return new clientFetch.FrontendApi(config);
2392
- }
2393
-
2394
- // src/util/onSubmitLogin.ts
2395
- async function onSubmitLogin({ config, flow }, {
2396
- setFlowContainer,
2397
- body,
2398
- onRedirect
2399
- }) {
2400
- var _a;
2401
- if (!config.sdk.url) {
2402
- throw new Error(
2403
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2404
- );
2405
- }
2406
- await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateLoginFlowRaw({
2407
- flow: flow.id,
2408
- updateLoginFlowBody: body
2409
- }).then(() => {
2410
- var _a2;
2411
- window.location.href = (_a2 = flow.return_to) != null ? _a2 : config.sdk.url + "/self-service/login/browser";
2412
- }).catch(
2413
- clientFetch.handleFlowError({
2414
- onRestartFlow: () => {
2415
- onRedirect(clientFetch.loginUrl(config), true);
2416
- },
2417
- onValidationError: (body2) => {
2418
- setFlowContainer({
2419
- config,
2420
- flow: body2,
2421
- flowType: clientFetch.FlowType.Login
2422
- });
2423
- },
2424
- onRedirect
2425
- })
2426
- );
2427
- }
2428
- async function onSubmitRegistration({ config, flow }, {
2429
- setFlowContainer,
2430
- body,
2431
- onRedirect
2432
- }) {
2433
- var _a;
2434
- if (!config.sdk.url) {
2435
- throw new Error(
2436
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2437
- );
2438
- }
2439
- const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
2440
- await client.updateRegistrationFlowRaw({
2441
- flow: flow.id,
2442
- updateRegistrationFlowBody: body
2443
- }).then(async (res) => {
2444
- const body2 = await res.value();
2445
- const didContinueWith = clientFetch.handleContinueWith(body2.continue_with, {
2446
- onRedirect
2447
- });
2448
- if (didContinueWith) {
2449
- return;
2450
- }
2451
- onRedirect(clientFetch.registrationUrl(config), true);
2452
- }).catch(
2453
- clientFetch.handleFlowError({
2454
- onRestartFlow: () => {
2455
- onRedirect(clientFetch.registrationUrl(config), true);
2456
- },
2457
- onValidationError: (body2) => {
2458
- setFlowContainer({
2459
- flow: body2,
2460
- flowType: clientFetch.FlowType.Registration,
2461
- config
2462
- });
2463
- },
2464
- onRedirect
2465
- })
2466
- );
2467
- }
2468
- async function onSubmitVerification({ config, flow }, {
2469
- setFlowContainer,
2470
- body,
2471
- onRedirect
2472
- }) {
2473
- var _a;
2474
- if (!config.sdk.url) {
2475
- throw new Error(
2476
- `Please supply your Ory Network SDK URL to the Ory Elements configuration.`
2477
- );
2478
- }
2479
- await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateVerificationFlowRaw({
2480
- flow: flow.id,
2481
- updateVerificationFlowBody: body
2482
- }).then(
2483
- async (res) => setFlowContainer({
2484
- flow: await res.value(),
2485
- flowType: clientFetch.FlowType.Verification,
2486
- config
2487
- })
2488
- ).catch(
2489
- clientFetch.handleFlowError({
2490
- onRestartFlow: () => {
2491
- onRedirect(clientFetch.verificationUrl(config), true);
2492
- },
2493
- onValidationError: (body2) => {
2494
- setFlowContainer({
2495
- flow: body2,
2496
- flowType: clientFetch.FlowType.Verification,
2497
- config
2498
- });
2499
- },
2500
- onRedirect
2501
- })
2502
- );
2503
- }
2504
- async function onSubmitRecovery({ config, flow }, {
2505
- setFlowContainer,
2506
- body,
2507
- onRedirect
2508
- }) {
2509
- var _a;
2510
- if (!config.sdk.url) {
2511
- throw new Error(
2512
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2513
- );
2514
- }
2515
- await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateRecoveryFlowRaw({
2516
- flow: flow.id,
2517
- updateRecoveryFlowBody: body
2518
- }).then(async (res) => {
2519
- const flow2 = await res.value();
2520
- const didContinueWith = clientFetch.handleContinueWith(flow2.continue_with, {
2521
- onRedirect
2522
- });
2523
- if (didContinueWith) {
2524
- return;
2525
- }
2526
- setFlowContainer({
2527
- flow: flow2,
2528
- flowType: clientFetch.FlowType.Recovery,
2529
- config
2530
- });
2531
- }).catch(
2532
- clientFetch.handleFlowError({
2533
- onRestartFlow: () => {
2534
- onRedirect(clientFetch.recoveryUrl(config), true);
2535
- },
2536
- onValidationError: (body2) => {
2537
- setFlowContainer({
2538
- flow: body2,
2539
- flowType: clientFetch.FlowType.Recovery,
2540
- config
2541
- });
2542
- },
2543
- onRedirect
2544
- })
2545
- );
2546
- }
2547
- async function onSubmitSettings({ config, flow }, {
2548
- setFlowContainer,
2549
- body,
2550
- onRedirect
2551
- }) {
2552
- var _a;
2553
- if (!config.sdk.url) {
2554
- throw new Error(
2555
- `Please supply your Ory Network SDK url to the Ory Elements configuration.`
2556
- );
2557
- }
2558
- const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
2559
- await client.updateSettingsFlowRaw({
2560
- flow: flow.id,
2561
- updateSettingsFlowBody: body
2562
- }).then(async (res) => {
2563
- const body2 = await res.value();
2564
- const didContinueWith = clientFetch.handleContinueWith(body2.continue_with, {
2565
- onRedirect
2566
- });
2567
- if (didContinueWith) {
2568
- return;
2569
- }
2570
- onRedirect(clientFetch.settingsUrl(config), true);
2571
- }).catch(
2572
- clientFetch.handleFlowError({
2573
- onRestartFlow: () => {
2574
- onRedirect(clientFetch.settingsUrl(config), true);
2575
- },
2576
- onValidationError: (body2) => {
2577
- setFlowContainer({
2578
- flow: body2,
2579
- flowType: clientFetch.FlowType.Settings,
2580
- config
2581
- });
2582
- },
2583
- onRedirect
2584
- })
2585
- );
2586
- }
2587
- function OryForm({ children, onAfterSubmit, nodes }) {
2685
+ function OryForm({ children, onAfterSubmit }) {
2588
2686
  var _a;
2589
2687
  const { Form } = useComponents();
2590
2688
  const flowContainer = useOryFlow();
2591
- const defaultNodes = nodes ? flowContainer.flow.ui.nodes.filter((node) => node.group === clientFetch.UiNodeGroupEnum.Default).concat(nodes) : flowContainer.flow.ui.nodes;
2592
- const methods = reactHookForm.useForm({
2593
- // TODO: Generify this, so we have typesafety in the submit handler.
2594
- defaultValues: computeDefaultValues(defaultNodes)
2595
- });
2689
+ const methods = reactHookForm.useFormContext();
2596
2690
  const intl = reactIntl.useIntl();
2597
2691
  const onRedirect = (url, external) => {
2598
2692
  if (external) {
@@ -2666,8 +2760,10 @@ function OryForm({ children, onAfterSubmit, nodes }) {
2666
2760
  if ("lookup_secret_confirm" in submitData || "lookup_secret_reveal" in submitData || "lookup_secret_regenerate" in submitData) {
2667
2761
  submitData.method = "lookup_secret";
2668
2762
  }
2669
- if ("link" in submitData || "unlink" in submitData) {
2670
- submitData.method = "oidc";
2763
+ if (submitData.method === "oidc") {
2764
+ submitData.upstream_parameters = {
2765
+ prompt: "select_account"
2766
+ };
2671
2767
  }
2672
2768
  if ("webauthn_remove" in submitData) {
2673
2769
  submitData.method = "webauthn";
@@ -2703,7 +2799,7 @@ function OryForm({ children, onAfterSubmit, nodes }) {
2703
2799
  defaultMessage: "No authentication methods are available for this request. Please contact the site or app owner."
2704
2800
  });
2705
2801
  }
2706
- return /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children: /* @__PURE__ */ jsxRuntime.jsx(
2802
+ return /* @__PURE__ */ jsxRuntime.jsx(
2707
2803
  Form.Root,
2708
2804
  {
2709
2805
  action: flowContainer.flow.ui.action,
@@ -2726,9 +2822,9 @@ function OryForm({ children, onAfterSubmit, nodes }) {
2726
2822
  )
2727
2823
  ] })
2728
2824
  }
2729
- ) });
2825
+ );
2730
2826
  }
2731
- var messageIdsToHide = [1040009];
2827
+ var messageIdsToHide = [1040009, 1060003, 1080003, 1010014, 1040005];
2732
2828
  function OryCardValidationMessages({ ...props }) {
2733
2829
  var _a;
2734
2830
  const { flow } = useOryFlow();
@@ -2741,9 +2837,21 @@ function OryCardValidationMessages({ ...props }) {
2741
2837
  }
2742
2838
  return /* @__PURE__ */ jsxRuntime.jsx(Message.Root, { ...props, children: messages == null ? void 0 : messages.map((message) => /* @__PURE__ */ jsxRuntime.jsx(Message.Content, { message }, message.id)) });
2743
2839
  }
2840
+ function OryFormProvider({
2841
+ children,
2842
+ nodes
2843
+ }) {
2844
+ const flowContainer = useOryFlow();
2845
+ const defaultNodes = nodes ? flowContainer.flow.ui.nodes.filter((node) => node.group === clientFetch.UiNodeGroupEnum.Default).concat(nodes) : flowContainer.flow.ui.nodes;
2846
+ const methods = reactHookForm.useForm({
2847
+ // TODO: Generify this, so we have typesafety in the submit handler.
2848
+ defaultValues: computeDefaultValues(defaultNodes)
2849
+ });
2850
+ return /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children });
2851
+ }
2744
2852
  function OryFormSection({ children, nodes }) {
2745
2853
  const { Card } = useComponents();
2746
- return /* @__PURE__ */ jsxRuntime.jsx(OryForm, { nodes, children: /* @__PURE__ */ jsxRuntime.jsx(Card.SettingsSection, { children }) });
2854
+ return /* @__PURE__ */ jsxRuntime.jsx(OryFormProvider, { nodes, children: /* @__PURE__ */ jsxRuntime.jsx(OryForm, { children: /* @__PURE__ */ jsxRuntime.jsx(Card.SettingsSection, { children }) }) });
2747
2855
  }
2748
2856
  function OryCardContent({ children }) {
2749
2857
  const { Card } = useComponents();
@@ -2775,38 +2883,18 @@ function OryCardContent({ children }) {
2775
2883
  function OryCard({ children }) {
2776
2884
  const { Card } = useComponents();
2777
2885
  if (children) {
2778
- return /* @__PURE__ */ jsxRuntime.jsx(Card.Root, { children });
2886
+ return /* @__PURE__ */ jsxRuntime.jsx(Card.Root, { children: /* @__PURE__ */ jsxRuntime.jsx(OryFormProvider, { children }) });
2779
2887
  }
2780
- return /* @__PURE__ */ jsxRuntime.jsxs(Card.Root, { children: [
2888
+ return /* @__PURE__ */ jsxRuntime.jsx(Card.Root, { children: /* @__PURE__ */ jsxRuntime.jsxs(OryFormProvider, { children: [
2781
2889
  /* @__PURE__ */ jsxRuntime.jsx(OryCardHeader, {}),
2782
2890
  /* @__PURE__ */ jsxRuntime.jsx(OryCardContent, {}),
2783
2891
  /* @__PURE__ */ jsxRuntime.jsx(OryCardFooter, {})
2784
- ] });
2892
+ ] }) });
2785
2893
  }
2786
2894
  function OryCardFooter() {
2787
2895
  const { Card } = useComponents();
2788
2896
  return /* @__PURE__ */ jsxRuntime.jsx(Card.Footer, {});
2789
2897
  }
2790
- function isChoosingMethod(uiNodes) {
2791
- return uiNodes.some(
2792
- (node) => "name" in node.attributes && node.attributes.name === "screen" && "value" in node.attributes && node.attributes.value === "previous"
2793
- ) || uiNodes.some(
2794
- (node) => node.group === clientFetch.UiNodeGroupEnum.IdentifierFirst && "name" in node.attributes && node.attributes.name === "identifier" && node.attributes.type === "hidden"
2795
- );
2796
- }
2797
- function filterZeroStepGroups(nodes) {
2798
- return nodes.filter((node) => node.group !== clientFetch.UiNodeGroupEnum.Oidc);
2799
- }
2800
- function getFinalNodes(uniqueGroups, selectedGroup) {
2801
- var _a, _b, _c;
2802
- const selectedNodes = selectedGroup ? (_a = uniqueGroups[selectedGroup]) != null ? _a : [] : [];
2803
- return [
2804
- ...(_b = uniqueGroups == null ? void 0 : uniqueGroups.identifier_first) != null ? _b : [],
2805
- ...(_c = uniqueGroups == null ? void 0 : uniqueGroups.default) != null ? _c : []
2806
- ].flat().filter(
2807
- (node) => "type" in node.attributes && node.attributes.type === "hidden"
2808
- ).concat(selectedNodes);
2809
- }
2810
2898
 
2811
2899
  // src/theme/default/utils/form.ts
2812
2900
  function isGroupImmediateSubmit(group) {
@@ -2815,13 +2903,10 @@ function isGroupImmediateSubmit(group) {
2815
2903
  function OryTwoStepCard() {
2816
2904
  var _a;
2817
2905
  const {
2818
- flow: { ui },
2819
- config
2906
+ flow: { ui }
2820
2907
  } = useOryFlow();
2821
- const choosingMethod = isChoosingMethod(ui.nodes);
2822
- const [selectedGroup, setSelectedGroup] = react.useState();
2823
2908
  const { Form } = useComponents();
2824
- const { flowType } = useOryFlow();
2909
+ const { flowType, formState, dispatchFormState } = useOryFlow();
2825
2910
  const nodeSorter = useNodeSorter();
2826
2911
  const sortNodes = (a, b) => nodeSorter(a, b, { flowType });
2827
2912
  const uniqueGroups = useNodesGroups(ui.nodes);
@@ -2838,38 +2923,42 @@ function OryTwoStepCard() {
2838
2923
  );
2839
2924
  const hasOidc = Boolean((_a = uniqueGroups.groups[clientFetch.UiNodeGroupEnum.Oidc]) == null ? void 0 : _a.length);
2840
2925
  const zeroStepGroups = filterZeroStepGroups(ui.nodes);
2841
- const finalNodes = getFinalNodes(uniqueGroups.groups, selectedGroup);
2842
- const step = selectedGroup ? 2 /* ExecuteAuthMethod */ : choosingMethod ? 1 /* ChooseAuthMethod */ : 0 /* ProvideIdentifier */;
2926
+ const finalNodes = formState.current === "method_active" ? getFinalNodes(uniqueGroups.groups, formState.method) : [];
2843
2927
  return /* @__PURE__ */ jsxRuntime.jsxs(OryCard, { children: [
2844
2928
  /* @__PURE__ */ jsxRuntime.jsx(OryCardHeader, {}),
2845
2929
  /* @__PURE__ */ jsxRuntime.jsxs(OryCardContent, { children: [
2846
2930
  /* @__PURE__ */ jsxRuntime.jsx(OryCardValidationMessages, {}),
2847
- step === 0 /* ProvideIdentifier */ && hasOidc && /* @__PURE__ */ jsxRuntime.jsx(OryFormSocialButtonsForm, {}),
2848
- /* @__PURE__ */ jsxRuntime.jsx(
2931
+ formState.current === "provide_identifier" && hasOidc && /* @__PURE__ */ jsxRuntime.jsx(OryFormSocialButtonsForm, {}),
2932
+ /* @__PURE__ */ jsxRuntime.jsxs(
2849
2933
  OryForm,
2850
2934
  {
2851
- onAfterSubmit: (method) => isGroupImmediateSubmit(method + "") ? setSelectedGroup(method) : void 0,
2852
- children: /* @__PURE__ */ jsxRuntime.jsxs(Form.Group, { children: [
2853
- step === 0 /* ProvideIdentifier */ && zeroStepGroups.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k)),
2854
- step === 1 /* ChooseAuthMethod */ && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2855
- flowType === clientFetch.FlowType.Login && /* @__PURE__ */ jsxRuntime.jsx(BackButton, { href: config.project.login_ui_url }),
2856
- /* @__PURE__ */ jsxRuntime.jsx(
2935
+ onAfterSubmit: (method) => isGroupImmediateSubmit(method + "") ? dispatchFormState({
2936
+ type: "action_select_method",
2937
+ method
2938
+ }) : void 0,
2939
+ children: [
2940
+ /* @__PURE__ */ jsxRuntime.jsxs(Form.Group, { children: [
2941
+ formState.current === "provide_identifier" && zeroStepGroups.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k)),
2942
+ formState.current === "select_method" && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
2857
2943
  AuthMethodList,
2858
2944
  {
2859
2945
  options,
2860
- setSelectedGroup
2946
+ setSelectedGroup: (group) => dispatchFormState({
2947
+ type: "action_select_method",
2948
+ method: group
2949
+ })
2861
2950
  }
2862
- )
2951
+ ) }),
2952
+ formState.current === "method_active" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2953
+ ui.nodes.filter((n) => n.type === "script").map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k)),
2954
+ finalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k))
2955
+ ] })
2863
2956
  ] }),
2864
- step === 2 /* ExecuteAuthMethod */ && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2865
- /* @__PURE__ */ jsxRuntime.jsx(BackButton, { onClick: () => setSelectedGroup(void 0) }),
2866
- finalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k))
2867
- ] })
2868
- ] })
2957
+ /* @__PURE__ */ jsxRuntime.jsx(OryCardFooter, {})
2958
+ ]
2869
2959
  }
2870
2960
  )
2871
- ] }),
2872
- /* @__PURE__ */ jsxRuntime.jsx(OryCardFooter, {})
2961
+ ] })
2873
2962
  ] });
2874
2963
  }
2875
2964
  function AuthMethodList({ options, setSelectedGroup }) {
@@ -2891,32 +2980,6 @@ function AuthMethodList({ options, setSelectedGroup }) {
2891
2980
  option
2892
2981
  ));
2893
2982
  }
2894
- var BackButton = ({ onClick, href }) => {
2895
- const {
2896
- flow: { ui }
2897
- } = useOryFlow();
2898
- const { Node: Node2 } = useComponents();
2899
- const nodeBackButton = ui.nodes.find(
2900
- (node) => (
2901
- // ("value" in node.attributes &&
2902
- // node.attributes.value === "profile:back") ||
2903
- "name" in node.attributes && node.attributes.name === "identifier" && node.group === "identifier_first"
2904
- )
2905
- );
2906
- if (!nodeBackButton) {
2907
- return null;
2908
- }
2909
- return /* @__PURE__ */ jsxRuntime.jsx(
2910
- Node2.CurrentIdentifierButton,
2911
- {
2912
- node: nodeBackButton,
2913
- attributes: nodeBackButton.attributes,
2914
- onClick,
2915
- type: onClick ? "button" : void 0,
2916
- href
2917
- }
2918
- );
2919
- };
2920
2983
  function OryFormGroupDivider() {
2921
2984
  const { Card } = useComponents();
2922
2985
  const {