Skip to content

Commit 8b901ec

Browse files
authored
feat: add support for captchas (#200)
1 parent 26d0f10 commit 8b901ec

5 files changed

Lines changed: 30 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { UiNode } from "@ory/client"
2+
import { isUiNodeTextAttributes } from "../../../ui"
3+
import { Node } from "./node"
4+
5+
interface CaptchaSectionProps {
6+
nodes: UiNode[]
7+
}
8+
9+
export function CaptchaSection({ nodes }: CaptchaSectionProps) {
10+
const filteredNodes = nodes.filter(
11+
(node) => (node.group as string) === "captcha",
12+
)
13+
return filteredNodes.map((node, k) => {
14+
if (
15+
isUiNodeTextAttributes(node.attributes) &&
16+
node.attributes.id === "captcha"
17+
) {
18+
return <div id={node.attributes.id} key={node.attributes.id}></div>
19+
}
20+
return <Node node={node} key={k} />
21+
})
22+
}

src/react-components/ory/helpers/node-script.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const useScriptNodes = ({ nodes }: { nodes: UiNode[] }) => {
66
useEffect(() => {
77
const scriptNodes = filterNodesByGroups({
88
nodes: nodes,
9-
groups: "webauthn",
9+
groups: ["webauthn", "captcha"],
1010
attributes: "text/javascript",
1111
withoutDefaultGroup: true,
1212
withoutDefaultAttributes: true,

src/react-components/ory/sections/link-section.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { JSX } from "react"
33

44
import { gridStyle } from "../../../theme"
55
import { FilterFlowNodes } from "../helpers/filter-flow-nodes"
6+
import { CaptchaSection } from "../helpers/captcha"
67

78
export interface LinkSectionProps {
89
nodes: UiNode[]
@@ -33,6 +34,7 @@ export const LinkSection = ({ nodes }: LinkSectionProps): JSX.Element => (
3334
}}
3435
/>
3536
</div>
37+
<CaptchaSection nodes={nodes} />
3638
<FilterFlowNodes
3739
filter={{
3840
nodes: nodes,

src/react-components/ory/sections/login-section.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ButtonLink, CustomHref } from "../../button-link"
77
import { FilterFlowNodes } from "../helpers/filter-flow-nodes"
88
import { hasPassword, hasIdentifierFirst } from "../helpers/utils"
99
import { SelfServiceFlow } from "../helpers/types"
10+
import { CaptchaSection } from "../helpers/captcha"
1011

1112
export interface LoginSectionProps {
1213
nodes: UiNode[]
@@ -71,6 +72,7 @@ export const LoginSection = ({
7172
</ButtonLink>
7273
)}
7374
</div>
75+
<CaptchaSection nodes={nodes} />
7476
<FilterFlowNodes
7577
filter={{
7678
nodes: nodes,

src/react-components/ory/sections/registration-section.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { JSX } from "react"
44
import { gridStyle } from "../../../theme"
55
import { FilterFlowNodes } from "../helpers/filter-flow-nodes"
66
import { hasPassword } from "../helpers/utils"
7+
import { CaptchaSection } from "../helpers/captcha"
78

89
export interface RegistrationSectionProps {
910
nodes: UiNode[]
@@ -23,6 +24,8 @@ export const RegistrationSection = ({
2324
}}
2425
/>
2526
</div>
27+
28+
<CaptchaSection nodes={nodes} />
2629
<FilterFlowNodes
2730
filter={{
2831
nodes: nodes,

0 commit comments

Comments
 (0)