Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for captchas #200

Merged
merged 15 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading