> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Authenticate with SMS

## Console Configuration

Toggle on "Phone Number" in [the Log in & User Profile section of the Dynamic Console](https://console.dynamic.xyz/dashboard/log-in-user-profile).

![](https://mintlify.s3.us-west-1.amazonaws.com/dynamic-docs/images/dashboard/console-sms-configuration.png)

By default, you can use Dynamics credentials to send SMS messages to your users. However, if you want to send beyond US & Canada, you will need to set up your own Twilio account. In order to do this, you toggle off "Use Dynamic's credentials" and a section will open up for you, where you can enter your own credentials.

## SMS & Embedded Wallets

When you enable SMS sign-up, you can also enable embedded wallets for your users. This means that when a user signs up with their phone number, they will also receive a wallet that they can use to interact with your application.

In order to ensure your end users are adequately protected against attacks like sim swaps, we highly encourage you to [enable account MFA (TOTP) via Google Authenticator](https://docs.dynamic.xyz/docs/react/authentication-methods/mfa).

## Prerequisites

Before this: create and initialize a Dynamic client (see [Creating a Dynamic Client](https://docs.dynamic.xyz/docs/javascript/reference/client/create-dynamic-client.md), [Initializing the Dynamic Client](https://docs.dynamic.xyz/docs/javascript/reference/client/initialize-dynamic-client.md)).

## Usage

> [tab] JavaScript
>
> ```javascript theme={"system"}
> import {
>   sendSmsOTP,
>   verifyOTP,
>   type OTPVerification
> } from '@dynamic-labs-sdk/client';
>
> // With the user's phone number, call sendSmsOTP to get the otpVerification
> // Then, once the user inputs the OTP code, call verifyOTP to verify it and complete the authentication
>
> let otpVerification: OTPVerification | null = null;
>
> const signInWithPhone = async () => {
>   // Replace 'US' with the user's country code and '1234567890' with the user's phone number
>   otpVerification = await sendSmsOTP({ isoCountryCode: 'US', phoneNumber: '1234567890' });
>   // Store the otpVerification for later use with the verifyOTP function
> };
>
> const handleVerifyOTP = async () => {
>   // Use the same otpVerification object that you got from the sendSmsOTP function
>   // Replace '123456' with the OTP code entered by the user
>   await verifyOTP({ otpVerification, verificationToken: '123456' });
> };
> ```

> [tab] React
>
> ```tsx theme={"system"}
> import { useSendSmsOTP, useVerifyOTP } from '@dynamic-labs-sdk/react-hooks';
> import type { CountryCode } from '@dynamic-labs-sdk/client';
> import { useState } from 'react';
>
> function SmsSignIn() {
>   const [phoneNumber, setPhoneNumber] = useState('');
>   const [isoCountryCode, setIsoCountryCode] = useState<CountryCode>('US');
>   const [otp, setOtp] = useState('');
>
>   const { mutate: sendSmsOTP, data: otpVerification, reset } = useSendSmsOTP();
>   const { mutate: verifyOTP, isPending: isVerifying } = useVerifyOTP();
>
>   if (otpVerification) {
>     return (
>       <div>
>         <input
>           value={otp}
>           onChange={(e) => setOtp(e.target.value)}
>           placeholder="Enter OTP"
>         />
>         <button onClick={() => verifyOTP({ otpVerification, verificationToken: otp })} disabled={isVerifying}>
>           Verify
>         </button>
>         <button onClick={() => reset()}>Back</button>
>       </div>
>     );
>   }
>
>   return (
>     <div>
>       <input
>         value={isoCountryCode}
>         onChange={(e) => setIsoCountryCode(e.target.value as CountryCode)}
>         placeholder="Country code (e.g. US)"
>       />
>       <input
>         value={phoneNumber}
>         onChange={(e) => setPhoneNumber(e.target.value)}
>         placeholder="Phone number"
>       />
>       <button onClick={() => sendSmsOTP({ isoCountryCode, phoneNumber })}>Send OTP</button>
>     </div>
>   );
> }
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.