feat(otp): add web otp auto-fill using sms credential API
This commit is contained in:
@@ -174,6 +174,33 @@ export function OtpVerifyForm({
|
||||
|
||||
const otpMessage = otpMessageFn();
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
const run = async () => {
|
||||
if (!('OTPCredential' in window)) return;
|
||||
|
||||
try {
|
||||
const ac = new AbortController();
|
||||
|
||||
const otp = await (navigator as any).credentials.get({
|
||||
otp: { transport: ['sms'] },
|
||||
signal: ac.signal,
|
||||
});
|
||||
|
||||
if (!cancelled && otp?.code) {
|
||||
setOtpCode(otp.code);
|
||||
}
|
||||
} catch { }
|
||||
};
|
||||
|
||||
run();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Stack alignItems="center">
|
||||
<AuthenticationCard>
|
||||
|
||||
Reference in New Issue
Block a user