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

# superun SMS Provider

> 使用 superun 云计算 整合 SMS 手机验证 - 自动配置并可直接使用

# superun SMS Provider

本指南说明如何使用 superun 云计算 整合 SMS 手机验证.当 superun 云计算 运行时,手机登录会自动启用,所有必要的验证钩子配置都会自动处理.

## 概述

superun 云计算 自动处理 SMS 验证设置:

* **自动启用手机登录**:当 superun 云计算 启动时,手机验证会自动启用
* **预配置验证钩子**:`send_sms` 钩子会自动配置并连接到 superun Gateway
* **无需手动配置**:您不需要手动创建 Edge Functions 或配置验证钩子
* **可直接使用**:只需在应用程序中整合客户端验证流程

## 客户端整合

在客户端应用程序中整合 SMS 验证流程.这是用户互动的前端整合逻辑:

```typescript theme={null}
import { supabase } from "@/integrations/supabase/client";

// 通过 SMS 发送 OTP - 当用户点击「发送验证码」时调用此函数
async function sendOTP(phone: string) {
  const { data, error } = await supabase.auth.signInWithOtp({
    phone: phone,
  });

  if (error) {
    throw new Error(error.message);
  }

  return data;
}

// 验证 OTP - 当用户点击「登入」或「验证」时调用此函数
async function verifyOTP(phone: string, token: string) {
  const { data, error } = await supabase.auth.verifyOtp({
    phone: phone,
    token: token,
    type: "sms",
  });

  if (error) {
    throw new Error(error.message);
  }

  return data;
}
```

**使用流程:**

1. **用户点击「发送验证码」**:调用 `sendOTP(phone)` 触发 SMS 发送.superun 云计算 会通过预配置的验证钩子自动处理 SMS 发送.
2. **用户输入验证码并点击「登录」**:调用 `verifyOTP(phone, token)` 验证代码并完成验证.

## 运作方式

1. **用户发起 SMS 验证**:当用户通过 `signInWithOtp()` 请求手机验证时,Supabase 会生成一个 OTP
2. **验证钩子自动触发**:superun 云计算 预配置的 `send_sms` 钩子会拦截验证事件
3. **自动发送 SMS**:钩子会使用 superun Gateway 发送 SMS 验证码
4. **用户验证代码**:用户输入代码,`verifyOtp()` 完成验证流程

<Note>
  所有后端基础设施（Edge Functions,验证钩子配置,webhook 验证和 SMS 闸道整合）都由 superun 云计算 自动处理.您只需要实作上述的客户端验证流程.
</Note>
