Skip to content

Commit 35e477b

Browse files
gaultierory-bot
authored andcommitted
fix: fix back button for recovery flow not showing in AX v1/v2
GitOrigin-RevId: 579ad35ee577cf141f0ac121e79aa42bd20eb693
1 parent 36d36f9 commit 35e477b

File tree

27 files changed

+714
-280
lines changed

27 files changed

+714
-280
lines changed

packages/elements-react/.stub-responses/recovery/code_recovery_v2/sent-code.json renamed to packages/elements-react/.stub-responses/recovery-v2/code/code-sent.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/elements-react/.stub-responses/recovery-v2/code/confirm-identifier.json

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/elements-react/.stub-responses/recovery/code_recovery_v2/initial-form.json renamed to packages/elements-react/.stub-responses/recovery-v2/code/initial-form.json

File renamed without changes.

packages/elements-react/.stub-responses/recovery/code_recovery_v2/missing-any-address.json renamed to packages/elements-react/.stub-responses/recovery-v2/code/missing-any-address.json

File renamed without changes.

packages/elements-react/.stub-responses/recovery-v2/code/select-identifier.json

Lines changed: 101 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/elements-react/.stub-responses/recovery/code_recovery_v2/wrong-code.json renamed to packages/elements-react/.stub-responses/recovery-v2/code/wrong-code.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/elements-react/src/components/form/form-helpers.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import { isUiNodeInputAttributes, UiNode } from "@ory/client-fetch"
55
import { FormValues } from "../../types"
66

7-
export function computeDefaultValues(nodes: UiNode[]): FormValues {
8-
return nodes.reduce<FormValues>((acc, node) => {
7+
export function computeDefaultValues(flow: {
8+
active?: string
9+
ui: { nodes: UiNode[] }
10+
}): FormValues {
11+
const defaults = flow.ui.nodes.reduce<FormValues>((acc, node) => {
912
const attrs = node.attributes
1013

1114
if (isUiNodeInputAttributes(attrs)) {
@@ -52,6 +55,11 @@ export function computeDefaultValues(nodes: UiNode[]): FormValues {
5255

5356
return acc
5457
}, {})
58+
59+
if (flow.active) {
60+
defaults.method = flow.active
61+
}
62+
return defaults
5563
}
5664

5765
export function unrollTrait<T extends string, V>(

packages/elements-react/src/components/form/form-provider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export function OryFormProvider({
2121

2222
const methods = useForm({
2323
// TODO: Generify this, so we have typesafety in the submit handler.
24-
defaultValues: computeDefaultValues(defaultNodes),
24+
defaultValues: computeDefaultValues({
25+
active: flowContainer.flow.active,
26+
ui: { nodes: defaultNodes },
27+
}),
2528
resolver: useOryFormResolver(),
2629
})
2730

packages/elements-react/src/components/form/form-resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { FormValues } from "../../types"
66
import { isUiNodeInputAttributes } from "@ory/client-fetch"
77

88
function isCodeResendRequest(data: FormValues) {
9-
// There are two types of resend - one
10-
return data.email ?? data.resend
9+
// There are three types of resend
10+
return data.email ?? data.resend ?? data.recovery_confirm_address
1111
}
1212

1313
/**

packages/elements-react/src/components/form/messages.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface OryCardValidationMessagesProps {
5252
export function OryCardValidationMessages({
5353
hiddenMessageIds = [
5454
1040009, 1060003, 1080003, 1010004, 1010014, 1040005, 1010016, 1010003,
55+
1060004, 1060005, 1060006,
5556
],
5657
}: OryCardValidationMessagesProps) {
5758
const { flow } = useOryFlow()

0 commit comments

Comments
 (0)