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();
|
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 (
|
return (
|
||||||
<Stack alignItems="center">
|
<Stack alignItems="center">
|
||||||
<AuthenticationCard>
|
<AuthenticationCard>
|
||||||
|
|||||||
Reference in New Issue
Block a user