6-Box Discrete OTP Code Verification
Authenticate two-factor challenges using prompt inputs with auto-advance and numeric masks.
ui.prompt() supports formatted numeric codes with validation and async verification.
export async function promptTwoFactorCode(userPhone: string) {
const res = await ui.prompt({
title: 'Two-Factor Authentication',
text: Enter the 6-digit security code sent to ${userPhone}:,
input: 'number',
placeholder: '123456',
validate: (val) => {
if (!val || String(val).length !== 6) {
return 'Please enter a valid 6-digit verification code.';
}
return undefined;
},
preConfirm: async (val) => {
const isValid = await api.verify2FA(String(val));
if (!isValid) throw new Error('Incorrect security code. Please check your SMS and try again.');
},
});
if (res.isConfirmed) {
toast.success('Two-factor authentication verified.');
}
}
`
Want to test these options live?
Launch the interactive playground to experiment with themes, positions, and live generators.