@nhost/react
Version:
Nhost React library
44 lines (43 loc) • 2.05 kB
TypeScript
import { PasswordlessOptions, SignInSmsPasswordlessHandlerResult, SignInSmsPasswordlessOtpHandlerResult, SignInSmsPasswordlessState } from '@nhost/nhost-js';
export interface SignInSmsPasswordlessHandler {
(phoneNumber: string, options?: PasswordlessOptions): Promise<SignInSmsPasswordlessHandlerResult>;
}
export interface SignInSmsPasswordlessOtpHandler {
(code: string): Promise<SignInSmsPasswordlessOtpHandlerResult>;
(phoneNumber: string, code: string): Promise<SignInSmsPasswordlessOtpHandlerResult>;
}
export interface SignInSmsPasswordlessHookResult extends SignInSmsPasswordlessState {
/** Sends a one-time code to the given phoneNumber */
signInSmsPasswordless: SignInSmsPasswordlessHandler;
sendOtp: SignInSmsPasswordlessOtpHandler;
}
/**
* Use the hook `useSignInSmsPasswordless` to sign in a user with a one-time password sent via SMS to a phone.
*
* 1. The `signInSmsPasswordless` action sends a one-time password to the given phone number.
* 2. The client is then awaiting the OTP. `needsOtp` equals true.
* 3. After the code is received by SMS, the client sends the code with `sendOtp`. On success, the client is authenticated, and `isSuccess` equals `true`.
*
* Any error is monitored through `isError` and `error`. While the `signInSmsPasswordless` and `sendOtp` actions are running, `isLoading` equals `true`.
*
* @example
* ```tsx
* const { signInSmsPasswordless, sendOtp, needsOtp, isLoading, isSuccess, isError, error } = useSignInSmsPasswordless()
*
* console.log({ isLoading, isSuccess, isError, error });
*
* const askCode = async (e) => {
* e.preventDefault();
* await signInSmsPasswordless('+32455555555');
* }
*
* const sendCode = async (e) => {
* e.preventDefault();
* await sendOtp('123456');
* }
* ```
*
* @docs https://docs.nhost.io/reference/react/use-sign-in-sms-passwordless
*/
export declare function useSignInSmsPasswordless(stateOptions?: PasswordlessOptions): SignInSmsPasswordlessHookResult;
//# sourceMappingURL=useSignInSmsPasswordless.d.ts.map