React
Learn how to use the Authsignal React SDK.
The Authsignal React SDK builds on top of the Web SDK by providing UI components which can be added to your React app.
An example of the UI components in a checkout flow.
Installation
AuthsignalProvider component
The AuthsignalProvider
component allows you to use the useAuthsignal hook. Render the AuthsignalProvider
component
at the root of your application so that it is available everywhere you need it.
The AuthsignalProvider
component accepts the following props:
Customize the design of the UI components.
useAuthsignal hook
The useAuthsignal
hook returns two functions, startChallenge
and startChallengeAsync
, that you can use to
trigger the authentication flow.
Both functions require a token
to be passed as an argument. The token
should be
returned by your server after tracking an action.
startChallenge
The startChallenge
function triggers the authentication flow.
As well as a token
, the startChallenge
function accepts the following callbacks:
A callback function that is called when the challenge is successful. It receives an object with a
token
property. This token
should be sent to your server to validate the
challenge.
A callback function that is called when the user cancels the challenge.
A callback function that is called when the token expires.
startChallengeAsync
Alternatively, you can use the startChallengeAsync
function, which returns a Promise
that resolves with a token
when the challenge is successful.
It will throw a ChallengeError
if the user cancels the challenge or the token expires.
Customizing the appearance
You can customize the appearance of the UI components by passing an appearance
prop to the AuthsignalProvider component.