Skip to content

Documentation / react-auth / useMfaEnrollment

Function: useMfaEnrollment()

useMfaEnrollment(): Object

Use this hook to enroll a user in MFA

Returns

Object

initEnrollmentWithSms - starts the MFA enrollment flow for SMS

initEnrollmentWithTotp - starts the MFA enrollment flow for TOTP

submitEnrollmentWithSms - completes the MFA enrollment flow for SMS

submitEnrollmentWithTotp - completes the MFA enrollment flow for TOTP

unenrollWithSms - unenrolls the SMS MFA method

unenrollWithTotp - unenrolls the TOTP MFA method

showMfaEnrollmentModal - opens the MFA enrollment modal

closeMfaEnrollmentModal - closes the MFA enrollment modal

closeMfaEnrollmentModal

closeMfaEnrollmentModal: () => void

Returns

void

initEnrollmentWithSms

initEnrollmentWithSms: (meta) => Promise<void>

Parameters

meta: Object

meta.phoneNumber: string

Returns

Promise<void>

initEnrollmentWithTotp

initEnrollmentWithTotp: () => Promise<Object>

Returns

Promise<Object>

authUrl

authUrl: string

secret

secret: string

showMfaEnrollmentModal

showMfaEnrollmentModal: () => void

Returns

void

submitEnrollmentWithSms

submitEnrollmentWithSms: (meta) => Promise<void>

Parameters

meta: Object

meta.mfaCode: string

meta.phoneNumber: string

Returns

Promise<void>

submitEnrollmentWithTotp

submitEnrollmentWithTotp: (meta) => Promise<void>

Parameters

meta: Object

meta.mfaCode: string

Returns

Promise<void>

unenrollWithSms

unenrollWithSms: () => Promise<void>

Returns

Promise<void>

unenrollWithTotp

unenrollWithTotp: () => Promise<void>

Returns

Promise<void>

Example

ts
const {initEnrollment} = useMfaEnrollment();

<button
  onClick={() => {
    initEnrollment(
      'sms',
      { phoneNumber: '<user-phone-number>' },
    );
  }}
>
  Enroll in SMS MFA
</button>

Example

ts
const {submitEnrollment} = useMfaEnrollment();

<button
  onClick={() => {
    submitEnrollment(
      'sms',
      { phoneNumber: '<user-phone-number>', mfaCode: '<user-mfa-code>' },
    );
  }}
>
  Enroll in SMS MFA
</button>

Example

ts
const {unenrollWithSms} = useMfaEnrollment();

<button
 onClick={() => {
   unenrollWithSms();
 }}
>
Unenroll in SMS MFA
</button>

Example

ts
const {unenrollWithTotp} = useMfaEnrollment();

<button
 onClick={() => {
   unenrollWithTotp();
 }}
>
 Unenroll in TOTP MFA
</button>