@ory/elements-react 1.0.0-next.14 → 1.0.0-next.16
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 +41 -0
- package/api-report/elements-react-theme.api.json +33 -0
- package/api-report/elements-react-theme.api.md +5 -2
- package/api-report/elements-react.api.json +115 -107
- package/api-report/elements-react.api.md +27 -12
- package/dist/index.d.mts +87 -71
- package/dist/index.d.ts +87 -71
- package/dist/index.js +505 -437
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +507 -439
- package/dist/index.mjs.map +1 -1
- package/dist/theme/default/index.css +62 -2
- package/dist/theme/default/index.css.map +1 -1
- package/dist/theme/default/index.d.mts +3 -1
- package/dist/theme/default/index.d.ts +3 -1
- package/dist/theme/default/index.js +884 -757
- package/dist/theme/default/index.js.map +1 -1
- package/dist/theme/default/index.mjs +837 -709
- package/dist/theme/default/index.mjs.map +1 -1
- package/package.json +2 -2
- package/tailwind.config.ts +1 -1
- package/api-report/temp/elements-react-client.api.md +0 -22
- package/api-report/temp/elements-react-theme.api.md +0 -131
- package/api-report/temp/elements-react.api.md +0 -406
package/dist/index.js
CHANGED
|
@@ -85,6 +85,82 @@ 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 findMethodWithMessage(nodes) {
|
|
111
|
+
var _a;
|
|
112
|
+
return (_a = nodes == null ? void 0 : nodes.filter((n) => !["default", "identifier_first"].includes(n.group))) == null ? void 0 : _a.find((node) => {
|
|
113
|
+
var _a2;
|
|
114
|
+
return ((_a2 = node.messages) == null ? void 0 : _a2.length) > 0;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function parseStateFromFlow(flow) {
|
|
118
|
+
switch (flow.flowType) {
|
|
119
|
+
case clientFetch.FlowType.Registration:
|
|
120
|
+
case clientFetch.FlowType.Login: {
|
|
121
|
+
const methodWithMessage = findMethodWithMessage(flow.flow.ui.nodes);
|
|
122
|
+
if (flow.flow.active == "link_recovery") {
|
|
123
|
+
return { current: "method_active", method: "link" };
|
|
124
|
+
} else if (flow.flow.active == "code_recovery") {
|
|
125
|
+
return { current: "method_active", method: "code" };
|
|
126
|
+
} else if (methodWithMessage) {
|
|
127
|
+
return { current: "method_active", method: methodWithMessage.group };
|
|
128
|
+
} else if (flow.flow.active && !["default", "identifier_first"].includes(flow.flow.active)) {
|
|
129
|
+
return { current: "method_active", method: flow.flow.active };
|
|
130
|
+
} else if (isChoosingMethod(flow.flow.ui.nodes)) {
|
|
131
|
+
return { current: "select_method" };
|
|
132
|
+
}
|
|
133
|
+
return { current: "provide_identifier" };
|
|
134
|
+
}
|
|
135
|
+
case clientFetch.FlowType.Recovery:
|
|
136
|
+
case clientFetch.FlowType.Verification:
|
|
137
|
+
if (flow.flow.active === "code" || flow.flow.active === "link") {
|
|
138
|
+
if (flow.flow.state === "choose_method") {
|
|
139
|
+
return { current: "provide_identifier" };
|
|
140
|
+
}
|
|
141
|
+
return { current: "method_active", method: flow.flow.active };
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case clientFetch.FlowType.Settings:
|
|
145
|
+
return { current: "settings" };
|
|
146
|
+
}
|
|
147
|
+
console.warn(
|
|
148
|
+
`[Ory/Elements React] Encountered an unknown form state on ${flow.flowType} flow with ID ${flow.flow.id}`
|
|
149
|
+
);
|
|
150
|
+
throw new Error("Unknown form state");
|
|
151
|
+
}
|
|
152
|
+
function formStateReducer(state, action) {
|
|
153
|
+
switch (action.type) {
|
|
154
|
+
case "action_flow_update":
|
|
155
|
+
return parseStateFromFlow(action.flow);
|
|
156
|
+
case "action_select_method":
|
|
157
|
+
return { current: "method_active", method: action.method };
|
|
158
|
+
}
|
|
159
|
+
return state;
|
|
160
|
+
}
|
|
161
|
+
function useFormStateReducer(flow) {
|
|
162
|
+
return react.useReducer(formStateReducer, parseStateFromFlow(flow));
|
|
163
|
+
}
|
|
88
164
|
function useOryFlow() {
|
|
89
165
|
const ctx = react.useContext(OryFlowContext);
|
|
90
166
|
if (!ctx) {
|
|
@@ -98,19 +174,21 @@ function OryFlowProvider({
|
|
|
98
174
|
...container
|
|
99
175
|
}) {
|
|
100
176
|
const [flowContainer, setFlowContainer] = react.useState(container);
|
|
177
|
+
const [formState, dispatchFormState] = useFormStateReducer(container);
|
|
101
178
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
102
179
|
OryFlowContext.Provider,
|
|
103
180
|
{
|
|
104
181
|
value: {
|
|
105
182
|
...flowContainer,
|
|
106
|
-
setFlowContainer: (
|
|
107
|
-
setFlowContainer(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
183
|
+
setFlowContainer: (flowContainer2) => {
|
|
184
|
+
setFlowContainer(flowContainer2);
|
|
185
|
+
dispatchFormState({
|
|
186
|
+
type: "action_flow_update",
|
|
187
|
+
flow: flowContainer2
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
formState,
|
|
191
|
+
dispatchFormState
|
|
114
192
|
},
|
|
115
193
|
children
|
|
116
194
|
}
|
|
@@ -359,7 +437,8 @@ var en_default = {
|
|
|
359
437
|
"settings.webauthn.info": "Hardware Tokens are used for second-factor authentication or as first-factor with Passkeys",
|
|
360
438
|
"settings.passkey.title": "Manage Passkeys",
|
|
361
439
|
"settings.passkey.description": "Manage your passkey settings",
|
|
362
|
-
"settings.passkey.info": "Manage your passkey settings"
|
|
440
|
+
"settings.passkey.info": "Manage your passkey settings",
|
|
441
|
+
"card.footer.select-another-method": "Select another method"
|
|
363
442
|
};
|
|
364
443
|
|
|
365
444
|
// src/locales/de.json
|
|
@@ -604,7 +683,8 @@ var de_default = {
|
|
|
604
683
|
"settings.title-profile": "Profileinstellungen",
|
|
605
684
|
"settings.title-totp": "Verwalten Sie die 2FA TOTP Authenticator-App",
|
|
606
685
|
"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"
|
|
686
|
+
"settings.webauthn.info": "Hardware-Tokens werden f\xFCr die Zweitfaktor-Authentifizierung oder als Erstfaktor-Authentifizierung mit Passkeys verwendet",
|
|
687
|
+
"card.footer.select-another-method": "Eine andere Methode verwenden"
|
|
608
688
|
};
|
|
609
689
|
|
|
610
690
|
// src/locales/es.json
|
|
@@ -849,7 +929,8 @@ var es_default = {
|
|
|
849
929
|
"settings.title-profile": "",
|
|
850
930
|
"settings.title-totp": "",
|
|
851
931
|
"settings.title-webauthn": "",
|
|
852
|
-
"settings.webauthn.info": ""
|
|
932
|
+
"settings.webauthn.info": "",
|
|
933
|
+
"card.footer.select-another-method": ""
|
|
853
934
|
};
|
|
854
935
|
|
|
855
936
|
// src/locales/fr.json
|
|
@@ -1094,7 +1175,8 @@ var fr_default = {
|
|
|
1094
1175
|
"settings.title-webauthn": "",
|
|
1095
1176
|
"settings.webauthn.description": "",
|
|
1096
1177
|
"settings.webauthn.info": "",
|
|
1097
|
-
"settings.webauthn.title": ""
|
|
1178
|
+
"settings.webauthn.title": "",
|
|
1179
|
+
"card.footer.select-another-method": ""
|
|
1098
1180
|
};
|
|
1099
1181
|
|
|
1100
1182
|
// src/locales/nl.json
|
|
@@ -1339,7 +1421,8 @@ var nl_default = {
|
|
|
1339
1421
|
"settings.title-webauthn": "",
|
|
1340
1422
|
"settings.webauthn.description": "",
|
|
1341
1423
|
"settings.webauthn.info": "",
|
|
1342
|
-
"settings.webauthn.title": ""
|
|
1424
|
+
"settings.webauthn.title": "",
|
|
1425
|
+
"card.footer.select-another-method": ""
|
|
1343
1426
|
};
|
|
1344
1427
|
|
|
1345
1428
|
// src/locales/pl.json
|
|
@@ -1584,7 +1667,8 @@ var pl_default = {
|
|
|
1584
1667
|
"settings.title-webauthn": "",
|
|
1585
1668
|
"settings.webauthn.description": "",
|
|
1586
1669
|
"settings.webauthn.info": "",
|
|
1587
|
-
"settings.webauthn.title": ""
|
|
1670
|
+
"settings.webauthn.title": "",
|
|
1671
|
+
"card.footer.select-another-method": ""
|
|
1588
1672
|
};
|
|
1589
1673
|
|
|
1590
1674
|
// src/locales/pt.json
|
|
@@ -1829,7 +1913,8 @@ var pt_default = {
|
|
|
1829
1913
|
"settings.title-webauthn": "",
|
|
1830
1914
|
"settings.webauthn.description": "",
|
|
1831
1915
|
"settings.webauthn.info": "",
|
|
1832
|
-
"settings.webauthn.title": ""
|
|
1916
|
+
"settings.webauthn.title": "",
|
|
1917
|
+
"card.footer.select-another-method": ""
|
|
1833
1918
|
};
|
|
1834
1919
|
|
|
1835
1920
|
// src/locales/sv.json
|
|
@@ -2074,7 +2159,8 @@ var sv_default = {
|
|
|
2074
2159
|
"settings.title-webauthn": "Hantera maskinvarutokens",
|
|
2075
2160
|
"settings.webauthn.description": "Hantera inst\xE4llningarna f\xF6r din maskinvarutoken",
|
|
2076
2161
|
"settings.webauthn.info": "H\xE5rdvarutokens anv\xE4nds f\xF6r andrafaktorsautentisering eller som f\xF6rstafaktor med l\xF6senordsnycklar",
|
|
2077
|
-
"settings.webauthn.title": "Hantera maskinvarutokens"
|
|
2162
|
+
"settings.webauthn.title": "Hantera maskinvarutokens",
|
|
2163
|
+
"card.footer.select-another-method": "V\xE4lj en annan metod"
|
|
2078
2164
|
};
|
|
2079
2165
|
|
|
2080
2166
|
// src/locales/index.ts
|
|
@@ -2133,126 +2219,369 @@ function OryCardHeader() {
|
|
|
2133
2219
|
const { Card } = useComponents();
|
|
2134
2220
|
return /* @__PURE__ */ jsxRuntime.jsx(Card.Header, {});
|
|
2135
2221
|
}
|
|
2136
|
-
function
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
return;
|
|
2144
|
-
}
|
|
2145
|
-
let i = 0;
|
|
2146
|
-
const ms = 250;
|
|
2147
|
-
const interval = setInterval(() => {
|
|
2148
|
-
i++;
|
|
2149
|
-
if (i > 20) {
|
|
2150
|
-
clearInterval(interval);
|
|
2151
|
-
throw new Error(
|
|
2152
|
-
"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."
|
|
2153
|
-
);
|
|
2154
|
-
}
|
|
2155
|
-
const fn2 = triggerToFunction(trigger);
|
|
2156
|
-
if (fn2) {
|
|
2157
|
-
clearInterval(interval);
|
|
2158
|
-
return fn2();
|
|
2222
|
+
function frontendClient(sdkUrl, opts = {}) {
|
|
2223
|
+
const config = new clientFetch.Configuration({
|
|
2224
|
+
...opts,
|
|
2225
|
+
basePath: sdkUrl,
|
|
2226
|
+
headers: {
|
|
2227
|
+
Accept: "application/json",
|
|
2228
|
+
...opts.headers
|
|
2159
2229
|
}
|
|
2160
|
-
}
|
|
2161
|
-
return;
|
|
2230
|
+
});
|
|
2231
|
+
return new clientFetch.FrontendApi(config);
|
|
2162
2232
|
}
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2233
|
+
|
|
2234
|
+
// src/util/onSubmitLogin.ts
|
|
2235
|
+
async function onSubmitLogin({ config, flow }, {
|
|
2236
|
+
setFlowContainer,
|
|
2237
|
+
body,
|
|
2238
|
+
onRedirect
|
|
2239
|
+
}) {
|
|
2240
|
+
var _a;
|
|
2241
|
+
if (!config.sdk.url) {
|
|
2242
|
+
throw new Error(
|
|
2243
|
+
`Please supply your Ory Network SDK url to the Ory Elements configuration.`
|
|
2167
2244
|
);
|
|
2168
|
-
return void 0;
|
|
2169
|
-
}
|
|
2170
|
-
const typedWindow = window;
|
|
2171
|
-
if (!(trigger in typedWindow) || !typedWindow[trigger]) {
|
|
2172
|
-
console.error(`The Ory SDK is missing a required function: ${trigger}.`);
|
|
2173
|
-
return void 0;
|
|
2174
2245
|
}
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2246
|
+
await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateLoginFlowRaw({
|
|
2247
|
+
flow: flow.id,
|
|
2248
|
+
updateLoginFlowBody: body
|
|
2249
|
+
}).then(() => {
|
|
2250
|
+
var _a2;
|
|
2251
|
+
window.location.href = (_a2 = flow.return_to) != null ? _a2 : config.sdk.url + "/self-service/login/browser";
|
|
2252
|
+
}).catch(
|
|
2253
|
+
clientFetch.handleFlowError({
|
|
2254
|
+
onRestartFlow: () => {
|
|
2255
|
+
onRedirect(clientFetch.loginUrl(config), true);
|
|
2256
|
+
},
|
|
2257
|
+
onValidationError: (body2) => {
|
|
2258
|
+
setFlowContainer({
|
|
2259
|
+
config,
|
|
2260
|
+
flow: body2,
|
|
2261
|
+
flowType: clientFetch.FlowType.Login
|
|
2262
|
+
});
|
|
2263
|
+
},
|
|
2264
|
+
onRedirect
|
|
2265
|
+
})
|
|
2266
|
+
);
|
|
2267
|
+
}
|
|
2268
|
+
async function onSubmitRecovery({ config, flow }, {
|
|
2269
|
+
setFlowContainer,
|
|
2270
|
+
body,
|
|
2271
|
+
onRedirect
|
|
2272
|
+
}) {
|
|
2273
|
+
var _a;
|
|
2274
|
+
if (!config.sdk.url) {
|
|
2275
|
+
throw new Error(
|
|
2276
|
+
`Please supply your Ory Network SDK url to the Ory Elements configuration.`
|
|
2179
2277
|
);
|
|
2180
|
-
return void 0;
|
|
2181
2278
|
}
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
groups2[node.group] = groupNodes;
|
|
2279
|
+
await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateRecoveryFlowRaw({
|
|
2280
|
+
flow: flow.id,
|
|
2281
|
+
updateRecoveryFlowBody: body
|
|
2282
|
+
}).then(async (res) => {
|
|
2283
|
+
const flow2 = await res.value();
|
|
2284
|
+
const didContinueWith = clientFetch.handleContinueWith(flow2.continue_with, {
|
|
2285
|
+
onRedirect
|
|
2286
|
+
});
|
|
2287
|
+
if (didContinueWith) {
|
|
2288
|
+
return;
|
|
2193
2289
|
}
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2290
|
+
setFlowContainer({
|
|
2291
|
+
flow: flow2,
|
|
2292
|
+
flowType: clientFetch.FlowType.Recovery,
|
|
2293
|
+
config
|
|
2294
|
+
});
|
|
2295
|
+
}).catch(
|
|
2296
|
+
clientFetch.handleFlowError({
|
|
2297
|
+
onRestartFlow: () => {
|
|
2298
|
+
onRedirect(clientFetch.recoveryUrl(config), true);
|
|
2299
|
+
},
|
|
2300
|
+
onValidationError: (body2) => {
|
|
2301
|
+
setFlowContainer({
|
|
2302
|
+
flow: body2,
|
|
2303
|
+
flowType: clientFetch.FlowType.Recovery,
|
|
2304
|
+
config
|
|
2305
|
+
});
|
|
2306
|
+
},
|
|
2307
|
+
onRedirect
|
|
2308
|
+
})
|
|
2199
2309
|
);
|
|
2200
|
-
return {
|
|
2201
|
-
groups,
|
|
2202
|
-
entries
|
|
2203
|
-
};
|
|
2204
2310
|
}
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2311
|
+
async function onSubmitRegistration({ config, flow }, {
|
|
2312
|
+
setFlowContainer,
|
|
2313
|
+
body,
|
|
2314
|
+
onRedirect
|
|
2315
|
+
}) {
|
|
2209
2316
|
var _a;
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2317
|
+
if (!config.sdk.url) {
|
|
2318
|
+
throw new Error(
|
|
2319
|
+
`Please supply your Ory Network SDK url to the Ory Elements configuration.`
|
|
2320
|
+
);
|
|
2321
|
+
}
|
|
2322
|
+
const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
|
|
2323
|
+
await client.updateRegistrationFlowRaw({
|
|
2324
|
+
flow: flow.id,
|
|
2325
|
+
updateRegistrationFlowBody: body
|
|
2326
|
+
}).then(async (res) => {
|
|
2327
|
+
const body2 = await res.value();
|
|
2328
|
+
const didContinueWith = clientFetch.handleContinueWith(body2.continue_with, {
|
|
2329
|
+
onRedirect
|
|
2330
|
+
});
|
|
2331
|
+
if (didContinueWith) {
|
|
2332
|
+
return;
|
|
2225
2333
|
}
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2334
|
+
onRedirect(clientFetch.registrationUrl(config), true);
|
|
2335
|
+
}).catch(
|
|
2336
|
+
clientFetch.handleFlowError({
|
|
2337
|
+
onRestartFlow: () => {
|
|
2338
|
+
onRedirect(clientFetch.registrationUrl(config), true);
|
|
2339
|
+
},
|
|
2340
|
+
onValidationError: (body2) => {
|
|
2341
|
+
setFlowContainer({
|
|
2342
|
+
flow: body2,
|
|
2343
|
+
flowType: clientFetch.FlowType.Registration,
|
|
2344
|
+
config
|
|
2345
|
+
});
|
|
2346
|
+
},
|
|
2347
|
+
onRedirect
|
|
2348
|
+
})
|
|
2239
2349
|
);
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2350
|
+
}
|
|
2351
|
+
async function onSubmitSettings({ config, flow }, {
|
|
2352
|
+
setFlowContainer,
|
|
2353
|
+
body,
|
|
2354
|
+
onRedirect
|
|
2355
|
+
}) {
|
|
2356
|
+
var _a;
|
|
2357
|
+
if (!config.sdk.url) {
|
|
2358
|
+
throw new Error(
|
|
2359
|
+
`Please supply your Ory Network SDK url to the Ory Elements configuration.`
|
|
2360
|
+
);
|
|
2361
|
+
}
|
|
2362
|
+
const client = frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {});
|
|
2363
|
+
await client.updateSettingsFlowRaw({
|
|
2364
|
+
flow: flow.id,
|
|
2365
|
+
updateSettingsFlowBody: body
|
|
2366
|
+
}).then(async (res) => {
|
|
2367
|
+
const body2 = await res.value();
|
|
2368
|
+
const didContinueWith = clientFetch.handleContinueWith(body2.continue_with, {
|
|
2369
|
+
onRedirect
|
|
2370
|
+
});
|
|
2371
|
+
if (didContinueWith) {
|
|
2372
|
+
return;
|
|
2373
|
+
}
|
|
2374
|
+
onRedirect(clientFetch.settingsUrl(config), true);
|
|
2375
|
+
}).catch(
|
|
2376
|
+
clientFetch.handleFlowError({
|
|
2377
|
+
onRestartFlow: () => {
|
|
2378
|
+
onRedirect(clientFetch.settingsUrl(config), true);
|
|
2379
|
+
},
|
|
2380
|
+
onValidationError: (body2) => {
|
|
2381
|
+
setFlowContainer({
|
|
2382
|
+
flow: body2,
|
|
2383
|
+
flowType: clientFetch.FlowType.Settings,
|
|
2384
|
+
config
|
|
2385
|
+
});
|
|
2386
|
+
},
|
|
2387
|
+
onRedirect
|
|
2388
|
+
})
|
|
2389
|
+
).catch((err) => {
|
|
2390
|
+
if (clientFetch.isResponseError(err)) {
|
|
2391
|
+
if (err.response.status === 401) {
|
|
2392
|
+
return onRedirect(
|
|
2393
|
+
clientFetch.loginUrl(config) + "?return_to=" + clientFetch.settingsUrl(config),
|
|
2394
|
+
true
|
|
2395
|
+
);
|
|
2396
|
+
}
|
|
2397
|
+
throw err;
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
async function onSubmitVerification({ config, flow }, {
|
|
2402
|
+
setFlowContainer,
|
|
2403
|
+
body,
|
|
2404
|
+
onRedirect
|
|
2405
|
+
}) {
|
|
2406
|
+
var _a;
|
|
2407
|
+
if (!config.sdk.url) {
|
|
2408
|
+
throw new Error(
|
|
2409
|
+
`Please supply your Ory Network SDK URL to the Ory Elements configuration.`
|
|
2410
|
+
);
|
|
2411
|
+
}
|
|
2412
|
+
await frontendClient(config.sdk.url, (_a = config.sdk.options) != null ? _a : {}).updateVerificationFlowRaw({
|
|
2413
|
+
flow: flow.id,
|
|
2414
|
+
updateVerificationFlowBody: body
|
|
2415
|
+
}).then(
|
|
2416
|
+
async (res) => setFlowContainer({
|
|
2417
|
+
flow: await res.value(),
|
|
2418
|
+
flowType: clientFetch.FlowType.Verification,
|
|
2419
|
+
config
|
|
2420
|
+
})
|
|
2421
|
+
).catch(
|
|
2422
|
+
clientFetch.handleFlowError({
|
|
2423
|
+
onRestartFlow: () => {
|
|
2424
|
+
onRedirect(clientFetch.verificationUrl(config), true);
|
|
2425
|
+
},
|
|
2426
|
+
onValidationError: (body2) => {
|
|
2427
|
+
setFlowContainer({
|
|
2428
|
+
flow: body2,
|
|
2429
|
+
flowType: clientFetch.FlowType.Verification,
|
|
2430
|
+
config
|
|
2431
|
+
});
|
|
2432
|
+
},
|
|
2433
|
+
onRedirect
|
|
2434
|
+
})
|
|
2435
|
+
);
|
|
2436
|
+
}
|
|
2437
|
+
function computeDefaultValues(nodes) {
|
|
2438
|
+
return nodes.reduce((acc, node) => {
|
|
2439
|
+
const attrs = node.attributes;
|
|
2440
|
+
if (clientFetch.isUiNodeInputAttributes(attrs)) {
|
|
2441
|
+
if (attrs.name === "method" || attrs.type === "submit" || typeof attrs.value === "undefined")
|
|
2442
|
+
return acc;
|
|
2443
|
+
const unrolled = unrollTrait({
|
|
2444
|
+
name: attrs.name,
|
|
2445
|
+
value: attrs.value
|
|
2446
|
+
});
|
|
2447
|
+
Object.assign(acc, unrolled != null ? unrolled : { [attrs.name]: attrs.value });
|
|
2448
|
+
}
|
|
2449
|
+
return acc;
|
|
2450
|
+
}, {});
|
|
2451
|
+
}
|
|
2452
|
+
function unrollTrait(input, output = {}) {
|
|
2453
|
+
const keys = input.name.split(".");
|
|
2454
|
+
if (!keys.length) return void 0;
|
|
2455
|
+
let current = output;
|
|
2456
|
+
keys.forEach((key, index) => {
|
|
2457
|
+
if (!key) return;
|
|
2458
|
+
current = current[key] = index === keys.length - 1 ? input.value : current[key] || {};
|
|
2459
|
+
});
|
|
2460
|
+
return output;
|
|
2461
|
+
}
|
|
2462
|
+
function triggerToWindowCall(trigger) {
|
|
2463
|
+
if (!trigger) {
|
|
2464
|
+
return;
|
|
2465
|
+
}
|
|
2466
|
+
const fn = triggerToFunction(trigger);
|
|
2467
|
+
if (fn) {
|
|
2468
|
+
fn();
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
let i = 0;
|
|
2472
|
+
const ms = 100;
|
|
2473
|
+
const interval = setInterval(() => {
|
|
2474
|
+
i++;
|
|
2475
|
+
if (i > 100) {
|
|
2476
|
+
clearInterval(interval);
|
|
2477
|
+
throw new Error(
|
|
2478
|
+
"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."
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
2481
|
+
const fn2 = triggerToFunction(trigger);
|
|
2482
|
+
if (fn2) {
|
|
2483
|
+
clearInterval(interval);
|
|
2484
|
+
return fn2();
|
|
2485
|
+
}
|
|
2486
|
+
}, ms);
|
|
2487
|
+
return;
|
|
2488
|
+
}
|
|
2489
|
+
function triggerToFunction(trigger) {
|
|
2490
|
+
if (typeof window === "undefined") {
|
|
2491
|
+
console.error(
|
|
2492
|
+
"The Ory SDK is missing a required function: window is undefined."
|
|
2493
|
+
);
|
|
2494
|
+
return void 0;
|
|
2495
|
+
}
|
|
2496
|
+
const typedWindow = window;
|
|
2497
|
+
if (!(trigger in typedWindow) || !typedWindow[trigger]) {
|
|
2498
|
+
console.error(`The Ory SDK is missing a required function: ${trigger}.`);
|
|
2499
|
+
return void 0;
|
|
2500
|
+
}
|
|
2501
|
+
const triggerFn = typedWindow[trigger];
|
|
2502
|
+
if (typeof triggerFn !== "function") {
|
|
2503
|
+
console.error(
|
|
2504
|
+
`The Ory SDK is missing a required function: ${trigger}. It is not a function.`
|
|
2505
|
+
);
|
|
2506
|
+
return void 0;
|
|
2507
|
+
}
|
|
2508
|
+
return triggerFn;
|
|
2509
|
+
}
|
|
2510
|
+
function useNodesGroups(nodes) {
|
|
2511
|
+
const groupSorter = useGroupSorter();
|
|
2512
|
+
const groups = react.useMemo(() => {
|
|
2513
|
+
var _a;
|
|
2514
|
+
const groups2 = {};
|
|
2515
|
+
for (const node of nodes) {
|
|
2516
|
+
if (node.type === "script") {
|
|
2517
|
+
continue;
|
|
2518
|
+
}
|
|
2519
|
+
const groupNodes = (_a = groups2[node.group]) != null ? _a : [];
|
|
2520
|
+
groupNodes.push(node);
|
|
2521
|
+
groups2[node.group] = groupNodes;
|
|
2522
|
+
}
|
|
2523
|
+
return groups2;
|
|
2524
|
+
}, [nodes]);
|
|
2525
|
+
const entries = react.useMemo(
|
|
2526
|
+
() => Object.entries(groups).sort(([a], [b]) => groupSorter(a, b)),
|
|
2527
|
+
[groups, groupSorter]
|
|
2528
|
+
);
|
|
2529
|
+
return {
|
|
2530
|
+
groups,
|
|
2531
|
+
entries
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
var NodeInput = ({
|
|
2535
|
+
node,
|
|
2536
|
+
attributes
|
|
2537
|
+
}) => {
|
|
2538
|
+
var _a;
|
|
2539
|
+
const { Node: Node2 } = useComponents();
|
|
2540
|
+
const { setValue } = reactHookForm.useFormContext();
|
|
2541
|
+
const {
|
|
2542
|
+
onloadTrigger,
|
|
2543
|
+
onclickTrigger,
|
|
2544
|
+
// These properties do not exist on input fields so we remove them (as we already have handled them).
|
|
2545
|
+
onclick: _ignoredOnclick,
|
|
2546
|
+
onload: _ignoredOnload,
|
|
2547
|
+
//
|
|
2548
|
+
...attrs
|
|
2549
|
+
} = attributes;
|
|
2550
|
+
const setFormValue = () => {
|
|
2551
|
+
if (attrs.value) {
|
|
2552
|
+
setValue(attrs.name, attrs.value);
|
|
2553
|
+
}
|
|
2554
|
+
};
|
|
2555
|
+
const hasRun = react.useRef(false);
|
|
2556
|
+
react.useEffect(
|
|
2557
|
+
() => {
|
|
2558
|
+
setFormValue();
|
|
2559
|
+
if (!hasRun.current && onloadTrigger) {
|
|
2560
|
+
hasRun.current = true;
|
|
2561
|
+
triggerToWindowCall(onloadTrigger);
|
|
2562
|
+
}
|
|
2563
|
+
},
|
|
2564
|
+
// TODO(jonas): make sure onloadTrigger is stable
|
|
2565
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- ignore onloadTrigger for now, until we make sure this is stable
|
|
2566
|
+
[]
|
|
2567
|
+
);
|
|
2568
|
+
const handleClick = () => {
|
|
2569
|
+
setFormValue();
|
|
2570
|
+
if (onclickTrigger) {
|
|
2571
|
+
triggerToWindowCall(onclickTrigger);
|
|
2572
|
+
}
|
|
2573
|
+
};
|
|
2574
|
+
const isSocial = (attrs.name === "provider" || attrs.name === "link") && node.group === "oidc";
|
|
2575
|
+
const isPinCodeInput = attrs.name === "code" && node.group === "code" || attrs.name === "totp_code" && node.group === "totp";
|
|
2576
|
+
const isResendNode = ((_a = node.meta.label) == null ? void 0 : _a.id) === 1070008;
|
|
2577
|
+
const isScreenSelectionNode = "name" in node.attributes && node.attributes.name === "screen";
|
|
2578
|
+
switch (attributes.type) {
|
|
2579
|
+
case clientFetch.UiNodeInputAttributesTypeEnum.Submit:
|
|
2580
|
+
case clientFetch.UiNodeInputAttributesTypeEnum.Button:
|
|
2581
|
+
if (isSocial) {
|
|
2582
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Node2.OidcButton, { attributes: attrs, node });
|
|
2583
|
+
}
|
|
2584
|
+
if (isResendNode || isScreenSelectionNode) {
|
|
2256
2585
|
return null;
|
|
2257
2586
|
}
|
|
2258
2587
|
return /* @__PURE__ */ jsxRuntime.jsx(Node2.Button, { attributes: attrs, node, onClick: handleClick });
|
|
@@ -2364,245 +2693,11 @@ function OryFormSocialButtonsForm() {
|
|
|
2364
2693
|
}
|
|
2365
2694
|
return /* @__PURE__ */ jsxRuntime.jsx(OryForm, { children: /* @__PURE__ */ jsxRuntime.jsx(OryFormOidcButtons, {}) });
|
|
2366
2695
|
}
|
|
2367
|
-
function
|
|
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
|
-
).catch((err) => {
|
|
2586
|
-
if (clientFetch.isResponseError(err)) {
|
|
2587
|
-
if (err.response.status === 401) {
|
|
2588
|
-
return onRedirect(
|
|
2589
|
-
clientFetch.loginUrl(config) + "?return_to=" + clientFetch.settingsUrl(config),
|
|
2590
|
-
true
|
|
2591
|
-
);
|
|
2592
|
-
}
|
|
2593
|
-
throw err;
|
|
2594
|
-
}
|
|
2595
|
-
});
|
|
2596
|
-
}
|
|
2597
|
-
function OryForm({ children, onAfterSubmit, nodes }) {
|
|
2696
|
+
function OryForm({ children, onAfterSubmit }) {
|
|
2598
2697
|
var _a;
|
|
2599
2698
|
const { Form } = useComponents();
|
|
2600
2699
|
const flowContainer = useOryFlow();
|
|
2601
|
-
const
|
|
2602
|
-
const methods = reactHookForm.useForm({
|
|
2603
|
-
// TODO: Generify this, so we have typesafety in the submit handler.
|
|
2604
|
-
defaultValues: computeDefaultValues(defaultNodes)
|
|
2605
|
-
});
|
|
2700
|
+
const methods = reactHookForm.useFormContext();
|
|
2606
2701
|
const intl = reactIntl.useIntl();
|
|
2607
2702
|
const onRedirect = (url, external) => {
|
|
2608
2703
|
if (external) {
|
|
@@ -2695,6 +2790,12 @@ function OryForm({ children, onAfterSubmit, nodes }) {
|
|
|
2695
2790
|
break;
|
|
2696
2791
|
}
|
|
2697
2792
|
}
|
|
2793
|
+
if ("password" in data) {
|
|
2794
|
+
methods.setValue("password", "");
|
|
2795
|
+
}
|
|
2796
|
+
if ("code" in data) {
|
|
2797
|
+
methods.setValue("code", "");
|
|
2798
|
+
}
|
|
2698
2799
|
onAfterSubmit == null ? void 0 : onAfterSubmit(data.method);
|
|
2699
2800
|
};
|
|
2700
2801
|
const hasMethods = flowContainer.flow.ui.nodes.filter((node) => {
|
|
@@ -2715,7 +2816,7 @@ function OryForm({ children, onAfterSubmit, nodes }) {
|
|
|
2715
2816
|
defaultMessage: "No authentication methods are available for this request. Please contact the site or app owner."
|
|
2716
2817
|
});
|
|
2717
2818
|
}
|
|
2718
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2819
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2719
2820
|
Form.Root,
|
|
2720
2821
|
{
|
|
2721
2822
|
action: flowContainer.flow.ui.action,
|
|
@@ -2738,9 +2839,9 @@ function OryForm({ children, onAfterSubmit, nodes }) {
|
|
|
2738
2839
|
)
|
|
2739
2840
|
] })
|
|
2740
2841
|
}
|
|
2741
|
-
)
|
|
2842
|
+
);
|
|
2742
2843
|
}
|
|
2743
|
-
var messageIdsToHide = [1040009];
|
|
2844
|
+
var messageIdsToHide = [1040009, 1060003, 1080003, 1010014, 1040005];
|
|
2744
2845
|
function OryCardValidationMessages({ ...props }) {
|
|
2745
2846
|
var _a;
|
|
2746
2847
|
const { flow } = useOryFlow();
|
|
@@ -2753,9 +2854,21 @@ function OryCardValidationMessages({ ...props }) {
|
|
|
2753
2854
|
}
|
|
2754
2855
|
return /* @__PURE__ */ jsxRuntime.jsx(Message.Root, { ...props, children: messages == null ? void 0 : messages.map((message) => /* @__PURE__ */ jsxRuntime.jsx(Message.Content, { message }, message.id)) });
|
|
2755
2856
|
}
|
|
2857
|
+
function OryFormProvider({
|
|
2858
|
+
children,
|
|
2859
|
+
nodes
|
|
2860
|
+
}) {
|
|
2861
|
+
const flowContainer = useOryFlow();
|
|
2862
|
+
const defaultNodes = nodes ? flowContainer.flow.ui.nodes.filter((node) => node.group === clientFetch.UiNodeGroupEnum.Default).concat(nodes) : flowContainer.flow.ui.nodes;
|
|
2863
|
+
const methods = reactHookForm.useForm({
|
|
2864
|
+
// TODO: Generify this, so we have typesafety in the submit handler.
|
|
2865
|
+
defaultValues: computeDefaultValues(defaultNodes)
|
|
2866
|
+
});
|
|
2867
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children });
|
|
2868
|
+
}
|
|
2756
2869
|
function OryFormSection({ children, nodes }) {
|
|
2757
2870
|
const { Card } = useComponents();
|
|
2758
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2871
|
+
return /* @__PURE__ */ jsxRuntime.jsx(OryFormProvider, { nodes, children: /* @__PURE__ */ jsxRuntime.jsx(OryForm, { children: /* @__PURE__ */ jsxRuntime.jsx(Card.SettingsSection, { children }) }) });
|
|
2759
2872
|
}
|
|
2760
2873
|
function OryCardContent({ children }) {
|
|
2761
2874
|
const { Card } = useComponents();
|
|
@@ -2787,38 +2900,18 @@ function OryCardContent({ children }) {
|
|
|
2787
2900
|
function OryCard({ children }) {
|
|
2788
2901
|
const { Card } = useComponents();
|
|
2789
2902
|
if (children) {
|
|
2790
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Card.Root, { children });
|
|
2903
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Card.Root, { children: /* @__PURE__ */ jsxRuntime.jsx(OryFormProvider, { children }) });
|
|
2791
2904
|
}
|
|
2792
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
2905
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Card.Root, { children: /* @__PURE__ */ jsxRuntime.jsxs(OryFormProvider, { children: [
|
|
2793
2906
|
/* @__PURE__ */ jsxRuntime.jsx(OryCardHeader, {}),
|
|
2794
2907
|
/* @__PURE__ */ jsxRuntime.jsx(OryCardContent, {}),
|
|
2795
2908
|
/* @__PURE__ */ jsxRuntime.jsx(OryCardFooter, {})
|
|
2796
|
-
] });
|
|
2909
|
+
] }) });
|
|
2797
2910
|
}
|
|
2798
2911
|
function OryCardFooter() {
|
|
2799
2912
|
const { Card } = useComponents();
|
|
2800
2913
|
return /* @__PURE__ */ jsxRuntime.jsx(Card.Footer, {});
|
|
2801
2914
|
}
|
|
2802
|
-
function isChoosingMethod(uiNodes) {
|
|
2803
|
-
return uiNodes.some(
|
|
2804
|
-
(node) => "name" in node.attributes && node.attributes.name === "screen" && "value" in node.attributes && node.attributes.value === "previous"
|
|
2805
|
-
) || uiNodes.some(
|
|
2806
|
-
(node) => node.group === clientFetch.UiNodeGroupEnum.IdentifierFirst && "name" in node.attributes && node.attributes.name === "identifier" && node.attributes.type === "hidden"
|
|
2807
|
-
);
|
|
2808
|
-
}
|
|
2809
|
-
function filterZeroStepGroups(nodes) {
|
|
2810
|
-
return nodes.filter((node) => node.group !== clientFetch.UiNodeGroupEnum.Oidc);
|
|
2811
|
-
}
|
|
2812
|
-
function getFinalNodes(uniqueGroups, selectedGroup) {
|
|
2813
|
-
var _a, _b, _c;
|
|
2814
|
-
const selectedNodes = selectedGroup ? (_a = uniqueGroups[selectedGroup]) != null ? _a : [] : [];
|
|
2815
|
-
return [
|
|
2816
|
-
...(_b = uniqueGroups == null ? void 0 : uniqueGroups.identifier_first) != null ? _b : [],
|
|
2817
|
-
...(_c = uniqueGroups == null ? void 0 : uniqueGroups.default) != null ? _c : []
|
|
2818
|
-
].flat().filter(
|
|
2819
|
-
(node) => "type" in node.attributes && node.attributes.type === "hidden"
|
|
2820
|
-
).concat(selectedNodes);
|
|
2821
|
-
}
|
|
2822
2915
|
|
|
2823
2916
|
// src/theme/default/utils/form.ts
|
|
2824
2917
|
function isGroupImmediateSubmit(group) {
|
|
@@ -2827,13 +2920,10 @@ function isGroupImmediateSubmit(group) {
|
|
|
2827
2920
|
function OryTwoStepCard() {
|
|
2828
2921
|
var _a;
|
|
2829
2922
|
const {
|
|
2830
|
-
flow: { ui }
|
|
2831
|
-
config
|
|
2923
|
+
flow: { ui }
|
|
2832
2924
|
} = useOryFlow();
|
|
2833
|
-
const choosingMethod = isChoosingMethod(ui.nodes);
|
|
2834
|
-
const [selectedGroup, setSelectedGroup] = react.useState();
|
|
2835
2925
|
const { Form } = useComponents();
|
|
2836
|
-
const { flowType } = useOryFlow();
|
|
2926
|
+
const { flowType, formState, dispatchFormState } = useOryFlow();
|
|
2837
2927
|
const nodeSorter = useNodeSorter();
|
|
2838
2928
|
const sortNodes = (a, b) => nodeSorter(a, b, { flowType });
|
|
2839
2929
|
const uniqueGroups = useNodesGroups(ui.nodes);
|
|
@@ -2850,38 +2940,42 @@ function OryTwoStepCard() {
|
|
|
2850
2940
|
);
|
|
2851
2941
|
const hasOidc = Boolean((_a = uniqueGroups.groups[clientFetch.UiNodeGroupEnum.Oidc]) == null ? void 0 : _a.length);
|
|
2852
2942
|
const zeroStepGroups = filterZeroStepGroups(ui.nodes);
|
|
2853
|
-
const finalNodes = getFinalNodes(uniqueGroups.groups,
|
|
2854
|
-
const step = selectedGroup ? 2 /* ExecuteAuthMethod */ : choosingMethod ? 1 /* ChooseAuthMethod */ : 0 /* ProvideIdentifier */;
|
|
2943
|
+
const finalNodes = formState.current === "method_active" ? getFinalNodes(uniqueGroups.groups, formState.method) : [];
|
|
2855
2944
|
return /* @__PURE__ */ jsxRuntime.jsxs(OryCard, { children: [
|
|
2856
2945
|
/* @__PURE__ */ jsxRuntime.jsx(OryCardHeader, {}),
|
|
2857
2946
|
/* @__PURE__ */ jsxRuntime.jsxs(OryCardContent, { children: [
|
|
2858
2947
|
/* @__PURE__ */ jsxRuntime.jsx(OryCardValidationMessages, {}),
|
|
2859
|
-
|
|
2860
|
-
/* @__PURE__ */ jsxRuntime.
|
|
2948
|
+
formState.current === "provide_identifier" && hasOidc && /* @__PURE__ */ jsxRuntime.jsx(OryFormSocialButtonsForm, {}),
|
|
2949
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2861
2950
|
OryForm,
|
|
2862
2951
|
{
|
|
2863
|
-
onAfterSubmit: (method) => isGroupImmediateSubmit(method + "") ?
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2952
|
+
onAfterSubmit: (method) => isGroupImmediateSubmit(method + "") ? dispatchFormState({
|
|
2953
|
+
type: "action_select_method",
|
|
2954
|
+
method
|
|
2955
|
+
}) : void 0,
|
|
2956
|
+
children: [
|
|
2957
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Form.Group, { children: [
|
|
2958
|
+
formState.current === "provide_identifier" && zeroStepGroups.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k)),
|
|
2959
|
+
formState.current === "select_method" && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2869
2960
|
AuthMethodList,
|
|
2870
2961
|
{
|
|
2871
2962
|
options,
|
|
2872
|
-
setSelectedGroup
|
|
2963
|
+
setSelectedGroup: (group) => dispatchFormState({
|
|
2964
|
+
type: "action_select_method",
|
|
2965
|
+
method: group
|
|
2966
|
+
})
|
|
2873
2967
|
}
|
|
2874
|
-
)
|
|
2968
|
+
) }),
|
|
2969
|
+
formState.current === "method_active" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2970
|
+
ui.nodes.filter((n) => n.type === "script").map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k)),
|
|
2971
|
+
finalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k))
|
|
2972
|
+
] })
|
|
2875
2973
|
] }),
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
finalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsxRuntime.jsx(Node, { node }, k))
|
|
2879
|
-
] })
|
|
2880
|
-
] })
|
|
2974
|
+
/* @__PURE__ */ jsxRuntime.jsx(OryCardFooter, {})
|
|
2975
|
+
]
|
|
2881
2976
|
}
|
|
2882
2977
|
)
|
|
2883
|
-
] })
|
|
2884
|
-
/* @__PURE__ */ jsxRuntime.jsx(OryCardFooter, {})
|
|
2978
|
+
] })
|
|
2885
2979
|
] });
|
|
2886
2980
|
}
|
|
2887
2981
|
function AuthMethodList({ options, setSelectedGroup }) {
|
|
@@ -2903,32 +2997,6 @@ function AuthMethodList({ options, setSelectedGroup }) {
|
|
|
2903
2997
|
option
|
|
2904
2998
|
));
|
|
2905
2999
|
}
|
|
2906
|
-
var BackButton = ({ onClick, href }) => {
|
|
2907
|
-
const {
|
|
2908
|
-
flow: { ui }
|
|
2909
|
-
} = useOryFlow();
|
|
2910
|
-
const { Node: Node2 } = useComponents();
|
|
2911
|
-
const nodeBackButton = ui.nodes.find(
|
|
2912
|
-
(node) => (
|
|
2913
|
-
// ("value" in node.attributes &&
|
|
2914
|
-
// node.attributes.value === "profile:back") ||
|
|
2915
|
-
"name" in node.attributes && node.attributes.name === "identifier" && node.group === "identifier_first"
|
|
2916
|
-
)
|
|
2917
|
-
);
|
|
2918
|
-
if (!nodeBackButton) {
|
|
2919
|
-
return null;
|
|
2920
|
-
}
|
|
2921
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2922
|
-
Node2.CurrentIdentifierButton,
|
|
2923
|
-
{
|
|
2924
|
-
node: nodeBackButton,
|
|
2925
|
-
attributes: nodeBackButton.attributes,
|
|
2926
|
-
onClick,
|
|
2927
|
-
type: onClick ? "button" : void 0,
|
|
2928
|
-
href
|
|
2929
|
-
}
|
|
2930
|
-
);
|
|
2931
|
-
};
|
|
2932
3000
|
function OryFormGroupDivider() {
|
|
2933
3001
|
const { Card } = useComponents();
|
|
2934
3002
|
const {
|