import { useMfa, useSyncMfaFlow, useDynamicContext } from "@dynamic-labs/sdk-react-core";
export function AccountTotpMfa() {
const {
addDevice,
authenticateDevice,
getUserDevices,
getRecoveryCodes,
completeAcknowledgement,
} = useMfa();
const { userWithMissingInfo } = useDynamicContext();
useSyncMfaFlow({
handler: async () => {
if (userWithMissingInfo?.scope?.includes("requiresAdditionalAuth")) {
const devices = await getUserDevices();
if (devices.length === 0) {
const { uri } = await addDevice();
// Render QR from `uri`, then prompt for OTP
return;
}
// Prompt for OTP
} else {
// MFA already satisfied; show recovery codes if needed
const codes = await getRecoveryCodes();
// Show `codes` to the user, then:
await completeAcknowledgement();
}
},
});
const verifyOtp = async (code: string) => {
await authenticateDevice({ code });
const codes = await getRecoveryCodes();
// Show `codes` to the user, then:
await completeAcknowledgement();
// Refresh device list
await getUserDevices();
};
return null;
}