useEnable2fa hook completes 2FA enrollment by verifying the code from the user’s authenticator app. Call it after useSetup2fa has returned the QR code and the user has scanned it.
Hook for enabling two-factor authentication with a verification code
useEnable2fa hook completes 2FA enrollment by verifying the code from the user’s authenticator app. Call it after useSetup2fa has returned the QR code and the user has scanned it.
import { useEnable2fa } from "@getpara/react-native-wallet";
import { useEnable2fa } from "@getpara/react-native-wallet";
import { useState } from "react";
import { View, TextInput, Button } from "react-native";
function Enable2faScreen() {
const [code, setCode] = useState("");
const { enable2faAsync, isPending } = useEnable2fa();
const handleEnable = async () => {
try {
await enable2faAsync({ verificationCode: code });
} catch (err) {
console.error(err);
}
};
return (
<View>
<TextInput value={code} onChangeText={setCode} placeholder="Enter code from app" keyboardType="number-pad" />
<Button title={isPending ? "Enabling..." : "Enable 2FA"} onPress={handleEnable} disabled={isPending} />
</View>
);
}