Skip to content

Commit

Permalink
feat: add support for captchas (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas authored Sep 4, 2024
1 parent 26d0f10 commit 8b901ec
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/react-components/ory/helpers/captcha.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { UiNode } from "@ory/client"
import { isUiNodeTextAttributes } from "../../../ui"
import { Node } from "./node"

interface CaptchaSectionProps {
nodes: UiNode[]
}

export function CaptchaSection({ nodes }: CaptchaSectionProps) {
const filteredNodes = nodes.filter(
(node) => (node.group as string) === "captcha",
)
return filteredNodes.map((node, k) => {
if (
isUiNodeTextAttributes(node.attributes) &&
node.attributes.id === "captcha"
) {
return <div id={node.attributes.id} key={node.attributes.id}></div>
}
return <Node node={node} key={k} />
})
}
2 changes: 1 addition & 1 deletion src/react-components/ory/helpers/node-script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const useScriptNodes = ({ nodes }: { nodes: UiNode[] }) => {
useEffect(() => {
const scriptNodes = filterNodesByGroups({
nodes: nodes,
groups: "webauthn",
groups: ["webauthn", "captcha"],
attributes: "text/javascript",
withoutDefaultGroup: true,
withoutDefaultAttributes: true,
Expand Down
2 changes: 2 additions & 0 deletions src/react-components/ory/sections/link-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { JSX } from "react"

import { gridStyle } from "../../../theme"
import { FilterFlowNodes } from "../helpers/filter-flow-nodes"
import { CaptchaSection } from "../helpers/captcha"

export interface LinkSectionProps {
nodes: UiNode[]
Expand Down Expand Up @@ -33,6 +34,7 @@ export const LinkSection = ({ nodes }: LinkSectionProps): JSX.Element => (
}}
/>
</div>
<CaptchaSection nodes={nodes} />
<FilterFlowNodes
filter={{
nodes: nodes,
Expand Down
2 changes: 2 additions & 0 deletions src/react-components/ory/sections/login-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ButtonLink, CustomHref } from "../../button-link"
import { FilterFlowNodes } from "../helpers/filter-flow-nodes"
import { hasPassword, hasIdentifierFirst } from "../helpers/utils"
import { SelfServiceFlow } from "../helpers/types"
import { CaptchaSection } from "../helpers/captcha"

export interface LoginSectionProps {
nodes: UiNode[]
Expand Down Expand Up @@ -71,6 +72,7 @@ export const LoginSection = ({
</ButtonLink>
)}
</div>
<CaptchaSection nodes={nodes} />
<FilterFlowNodes
filter={{
nodes: nodes,
Expand Down
3 changes: 3 additions & 0 deletions src/react-components/ory/sections/registration-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { JSX } from "react"
import { gridStyle } from "../../../theme"
import { FilterFlowNodes } from "../helpers/filter-flow-nodes"
import { hasPassword } from "../helpers/utils"
import { CaptchaSection } from "../helpers/captcha"

export interface RegistrationSectionProps {
nodes: UiNode[]
Expand All @@ -23,6 +24,8 @@ export const RegistrationSection = ({
}}
/>
</div>

<CaptchaSection nodes={nodes} />
<FilterFlowNodes
filter={{
nodes: nodes,
Expand Down

0 comments on commit 8b901ec

Please sign in to comment.