// From CDN
const guard = new AuthingMFAFactory.AuthingMFA({
appId: 'AUTHING_APP_ID'
})
// From npm
import { AuthingMFAProvider } from '@authing/mfa-component-react'
import '@authing/mfa-component-react/dist/index.min.css'
function App() {
return (
<AuthingMFAProvider
appId="AUTHING_APP_ID"
>
<RouterComponent></RouterComponent>
</AuthingMFAProvider>
)
}
// use Authing MFA APIs in Components
import { useEffect } from 'react'
import { useAuthingMFA } from '@authing/mfa-component-react'
export default function MFA() {
const authingMFA = useAuthingMFA()
useEffect(() => {
authingMFA.start({
el: document.querySelector('#authing-mfa-container'),
mfaTriggerData: {}
})
authingMFA.on('load', function () {
console.log('Authing MFA load')
})
authingMFA.on('mount', function () {
console.log('Authing MFA mount: ', document.querySelector('.authing-mfa-content'))
})
authingMFA.on('unmount', function () {
console.log('Authing MFA unmount')
})
authingMFA.on('success', function (code, data) {
console.log('Authing MFA success: ', code, data)
})
authingMFA.on('fail', function (message) {
console.log('Authing MFA fail: ', message)
})
authingMFA.on('saveRecoveryCode', function () {
console.log('Authing MFA saveRecoveryCode')
})
}, [])
return <div id="authing-mfa-container"></div>
}