Two-Factor

KS
Last updated 4 months ago

Add two-factor authentication anywhere in your application.

The same two-factor authentication used by Mason Login and Register features can be leveraged to protect any high-value action in your application.

Integration and Setup

See Authy Integration for setup instructions.

Authy User ID

In order to perform two-factor authentication, you must provide an authyUserId string as a prop. This should be the authyUserId of the user who is performing the action you want to protect. If you're using Mason Register, you received this value upon successful registration.

Sending the 2FA Request

The two-factor authentication request will be dispatched when the Mason Two-Factor feature mounts - so don't render it until you're ready to perform the authentication.

Server-side Validation

See Authy Server-side Validation.

Example

import React from 'react';
import { TwoFactor } from 'mason-library';
class Checkout extends React.Component {
state = {
twoFactor: false
}
...
render() {
if (this.state.twoFactor) {
const { user: { authyUserId } } = this.props;
return <TwoFactor id="YOUR_COMPONENT_ID"
authyUserId={authyUserId}
didReceiveData={() => {
//2FA success, complete purchase
}}/>;
} else {
...
}
}
}