useOtpCredential
Requests an OTP credential from the user agent.
Usage
import { useOtpCredential } from "@siberiacancode/reactuse";
const otp = useOtpCredential();Example
const otp = useOtpCredential();
return (
<button onClick={() => otp.get()}>
{otp.supported ? "Read SMS code" : "Not supported"}
</button>
);onSuccess:
const otp = useOtpCredential({
onSuccess: (credential) => console.log(credential),
});onError:
const otp = useOtpCredential({
onError: (error) => console.error(error),
});Notes
- Hook uses the navigator.credentials API.
Type Declarations
export type UseOtpCredentialCallback = (otp: Credential | null) => void;
export interface UseOtpCredentialParams {
onError?: (error: any) => void;
onSuccess?: (credential: Credential | null) => void;
}
export interface UseOtpCredentialReturn {
abort: AbortController["abort"];
supported: boolean;
get: () => Promise<Credential | null>;
}
export interface UseOtpCredential {
(callback?: UseOtpCredentialCallback): UseOtpCredentialReturn;
(params?: UseOtpCredentialParams): UseOtpCredentialReturn;
}
export declare const useOtpCredential: UseOtpCredential;