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

# Phone Login

> Implementing custom phone number authentication with Para

export const Card = ({imgUrl, iconUrl, fontAwesomeIcon, title, description, href, horizontal = false}) => {
  return <div className="relative group my-2" style={{
    padding: "1px",
    background: "#e5e7eb",
    borderRadius: "12px"
  }} onMouseOver={e => {
    e.currentTarget.style.background = "linear-gradient(45deg, #FF4E00, #874AE3)";
  }} onMouseOut={e => {
    e.currentTarget.style.background = "#e5e7eb";
  }}>
      <a href={href} className={`
          block not-prose font-normal h-full
          bg-white dark:bg-background-dark 
          overflow-hidden w-full cursor-pointer
          flex ${horizontal ? "flex-row" : "flex-col"}
        `} style={{
    borderRadius: "11px"
  }}>
        {(imgUrl || iconUrl) && <div className={`
              relative overflow-hidden flex-shrink-0
              ${horizontal ? "rounded-l" : ""}
              ${!imgUrl ? "bg-white dark:bg-background-dark p-4" : ""}
            `} style={{
    width: horizontal ? "30%" : "100%"
  }}>
            {imgUrl && <img src={`https://mintlify.s3-us-west-1.amazonaws.com/getpara${imgUrl}`} alt={title} className="w-full h-full object-cover" />}
            {(iconUrl || fontAwesomeIcon) && <div className={`
                ${imgUrl ? "absolute inset-0" : ""}
                flex items-center justify-center
              `}>
                <div className="relative w-8 h-8">
                  <img src={iconUrl ? `https://mintlify.s3-us-west-1.amazonaws.com/getpara${iconUrl}` : fontAwesomeIcon} alt={title} className="w-full h-full object-contain" style={{
    filter: "brightness(0) invert(1)"
  }} />
                </div>
              </div>}
          </div>}
        <div className={`
            flex-grow px-6 py-5
            ${horizontal && (imgUrl || iconUrl) ? "flex flex-col justify-center" : ""}
          `} style={{
    width: horizontal ? "70%" : "100%"
  }}>
          {title && <h2 className="font-semibold text-base text-gray-800 dark:text-white">{title}</h2>}
          {description && <div className={`
              font-normal text-sm text-gray-600 dark:text-gray-400 leading-6
              ${horizontal || !imgUrl && !iconUrl ? "mt-0" : "mt-1"}
            `}>
              <p>{description}</p>
            </div>}
        </div>
      </a>
    </div>;
};

export const Link = ({href, label}) => <a href={href} style={{
  display: "inline-block",
  position: "relative",
  color: "#000000",
  fontWeight: 600,
  cursor: "pointer",
  borderBottom: "none",
  textDecoration: "none"
}} onMouseEnter={e => {
  e.currentTarget.querySelector("#underline").style.height = "2px";
}} onMouseLeave={e => {
  e.currentTarget.querySelector("#underline").style.height = "1px";
}}>
    {label}
    <span id="underline" style={{
  position: "absolute",
  left: 0,
  bottom: 0,
  width: "100%",
  height: "1px",
  borderRadius: "2px",
  background: "linear-gradient(45deg, #FF4E00, #874AE3)",
  transition: "height 0.3s"
}}></span>

  </a>;

## Introduction

Para supports phone number authentication, allowing users to verify their identity using SMS verification codes. This guide demonstrates how to implement a custom phone authentication flow with your own UI components.

## Implementation Process

Follow these steps to implement custom phone authentication:

### 1. Check User Status

First, determine if the user already exists in your system:

```typescript theme={null}
const checkUserExists = async (phoneNumber: string) => {
  const isExistingUser = await para.checkIfUserExists({ phoneNumber });
  
  if (isExistingUser) {
    // Proceed with login flow for existing user
  } else {
    // Proceed with signup flow for new user
  }
};
```

### 2. Handle Existing User Login

For existing users, initiate the login process:

```typescript theme={null}
const loginExistingUser = async (phoneNumber: string) => {
  // Request SMS verification code to be sent
  await para.initiateUserLogin({ phoneNumber });
  
  // Proceed to verification step
};
```

### 3. Handle New User Registration

For new users, start the registration process:

```typescript theme={null}
const registerNewUser = async (phoneNumber: string) => {
  // Create new user with provided phone number
  await para.createUser({ phoneNumber });
  
  // SMS verification code will be sent
  // Proceed to verification step
};
```

### 4. Verify Phone Number and Complete Setup

After the user receives the SMS verification code:

```typescript theme={null}
const verifyAndCreateWallet = async (phoneNumber: string, verificationCode: string) => {
  try {
    // For new users:
    const setupUrl = await para.verifyPhoneNumber({ 
      phoneNumber, 
      verificationCode 
    });
    
    if (setupUrl) {
      // Open popup for passkey creation
      const popupWindow = window.open(setupUrl, "signUpPopup", "popup=true");
      
      // Wait for passkey setup and wallet creation
      await para.waitForPasskeyAndCreateWallet();
    }
    
    // For existing users:
    // const { needsWallet } = await para.verifyPhoneAndLogin({
    //   phoneNumber,
    //   verificationCode
    // });
    //
    // if (needsWallet) {
    //   await para.createWallet({ type: WalletType.EVM, skipDistribute: false });
    // }
    
    // Get user wallet information
    const wallets = Object.values(await para.getWallets());
  } catch (error) {
    // Handle verification errors
  }
};
```

## Example

For a complete working example of custom email authentication with Para, check out our sample project:

<Card horizontal title="Custom Phone Authentication Example" imgUrl="/images/v1/custom-ui-phone.png" href="https://github.com/getpara/examples-hub/tree/main/web/with-react-nextjs/custom-phone-auth" description="Explore a full implementation of custom email authentication using React and Next.js." />

## Next Steps

After integrating Para, you can explore other features and integrations to enhance your Para experience.

<CardGroup cols={3}>
  <Card title="EVM Integration" imgUrl="/images/v1/network-evm.png" href="/v1/web/guides/evm" description="Learn how to use Para with EVM-compatible libraries like ethers.js, viem, and wagmi." />

  <Card title="Solana Integration" imgUrl="/images/v1/network-solana.png" href="/v1/web/guides/solana" description="Discover how to integrate Para with solana-web3.js." />

  <Card title="Cosmos Integration" imgUrl="/images/v1/network-cosmos.png" href="/v1/web/guides/cosmos" description="Explore Para integration with Cosmos ecosystem using CosmJS, Cosmos Kit, and Graz." />
</CardGroup>
