React
useSignInSmsPasswordless()
Use the hook useSignInSmsPasswordless
to sign in a user with a one-time password sent via SMS to a phone.
- The
signInSmsPasswordless
action sends a one-time password to the given phone number. - The client is then awaiting the OTP.
needsOtp
equals true. - After the code is received by SMS, the client sends the code with
sendOtp
. On success, the client is authenticated, andisSuccess
equalstrue
.
Any error is monitored through isError
and error
. While the signInSmsPasswordless
and sendOtp
actions are running, isLoading
equals true
.
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')
}
Parameters
stateOptions optional PasswordlessOptions