{"id":17084673,"url":"https://github.com/authsignal/authsignal-react","last_synced_at":"2025-04-12T21:26:19.335Z","repository":{"id":257808201,"uuid":"865794773","full_name":"authsignal/authsignal-react","owner":"authsignal","description":"React components for Authsignal","archived":false,"fork":false,"pushed_at":"2024-12-17T00:34:23.000Z","size":243,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T19:46:06.118Z","etag":null,"topics":["2fa","authentication","mfa","next","nextjs","passkey","passkeys","react","remix","typescript","webauthn"],"latest_commit_sha":null,"homepage":"https://authsignal.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/authsignal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-01T06:32:01.000Z","updated_at":"2024-11-11T01:20:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"e9a214cf-0f1f-4a28-ad40-fd6b0302da0d","html_url":"https://github.com/authsignal/authsignal-react","commit_stats":null,"previous_names":["authsignal/authsignal-react"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/authsignal%2Fauthsignal-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/authsignal%2Fauthsignal-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/authsignal%2Fauthsignal-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/authsignal%2Fauthsignal-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/authsignal","download_url":"https://codeload.github.com/authsignal/authsignal-react/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248633465,"owners_count":21136872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2fa","authentication","mfa","next","nextjs","passkey","passkeys","react","remix","typescript","webauthn"],"created_at":"2024-10-14T13:09:12.390Z","updated_at":"2025-04-12T21:26:19.312Z","avatar_url":"https://github.com/authsignal.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Authsignal React SDK\n\nReact components for [Authsignal](https://authsignal.com).\n\n[Documentation](https://docs.authsignal.com/sdks/client/react)\n\n## Installation\nAdd `@authsignal/react` to your `package.json` dependencies.\n\n### NPM\n```bash\nnpm install @authsignal/react\n```\n\n### Yarn\n```bash\nyarn add @authsignal/react\n```\n\n## Usage\nRender the `AuthsignalProvider` component at the root of your app.\n\n```jsx\nimport { Authsignal } from '@authsignal/react';\n\nfunction App() {\n  return (\n    \u003cAuthsignalProvider tenantId=\"YOUR_TENANT_ID\" baseUrl=\"YOUR_BASE_URL\"\u003e\n      \u003cCheckout /\u003e\n    \u003c/AuthsignalProvider\u003e\n  );\n}\n```\nImport the `useAuthsignal` hook in your component.\n\nThen pass the `challengeOptions` returned from your server to the `startChallenge` function.\n\n```jsx\nimport { useAuthsignal } from '@authsignal/react';\n\nexport function Checkout() {\n  const { startChallenge } = useAuthsignal();\n\n  const handlePayment = async () =\u003e {\n    const response = await fetch('/api/payment', {\n      method: 'POST',\n      headers: {\n        'Content-Type': 'application/json',\n      },\n    });\n\n    const data = await response.json();\n\n    if (data.token) {\n       startChallenge({\n          token: data.token,\n          onChallengeSuccess: ({ token }) =\u003e {\n            // Challenge was successful\n          },\n          onCancel: () =\u003e {\n            // User cancelled the challenge\n          },\n          onTokenExpired: () =\u003e {\n            // Token expired\n          },\n        });\n    }\n  };\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton type=\"button\" onClick={handlePayment}\u003ePay\u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nAlternatively, you can use the `startChallengeAsync` function to work with promises.\n\n```jsx\nimport { useAuthsignal, ChallengeError } from '@authsignal/react';\n\nexport function Checkout() {\n  const { startChallengeAsync } = useAuthsignal();\n\n  const handlePayment = async () =\u003e {\n\n    const response = await fetch('/api/payment', {\n      method: 'POST',\n      headers: {\n        'Content-Type': 'application/json',\n      },\n    });\n\n    const data = await response.json();\n\n    if (data.token) {\n      try {\n        const { token } = await startChallengeAsync({\n          token: data.token,\n        });\n\n        // Challenge was successful\n      } catch (e) {\n        if (e instanceof ChallengeError) {\n          if (e.code === \"USER_CANCELED\") {\n            // User cancelled the challenge\n          } else if (e.code === \"TOKEN_EXPIRED\") {\n            // Token expired\n          }\n        }\n      }\n    }\n  };\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton type=\"button\" onClick={handlePayment}\u003ePay\u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthsignal%2Fauthsignal-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauthsignal%2Fauthsignal-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthsignal%2Fauthsignal-react/lists"}