🔐 认证接口
POST
/api/auth/login
用户登录
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| string | 是 | 用户邮箱 | |
| password | string | 是 | 用户密码 |
请求示例
POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}
响应示例
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_in": 3600,
"user": {
"id": "user-uuid",
"email": "user@example.com",
"created_at": "2024-01-01T00:00:00Z"
}
}
POST
/api/auth/register
用户注册
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| string | 是 | 用户邮箱 | |
| password | string | 是 | 密码(至少8位,包含字母和数字) |
| metadata | object | 否 | 用户元数据 |
👑 会员接口
GET
/api/membership/validate
验证会员状态
请求头
| 头部名称 | 值 | 说明 |
|---|---|---|
| Authorization | Bearer {access_token} | 用户访问令牌 |
响应示例
{
"tier": "pro",
"permissions": {
"maxProjects": 50,
"maxDraftsPerDay": 200,
"advancedFeatures": true,
"cloudSync": true
},
"expiresAt": "2024-12-31T23:59:59Z",
"signature": "signature-hash",
"validatedAt": "2024-01-01T12:00:00Z",
"isValid": true
}
🏥 健康检查
GET
/api/health
检查服务状态
响应示例
{
"status": "healthy",
"service": "jydraft-pages-functions",
"timestamp": "2024-01-01T12:00:00Z",
"version": "2.0.0",
"platform": "cloudflare-pages"
}
💻 示例代码
JavaScript/TypeScript
// 登录示例
const login = async (email, password) => {
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email, password })
});
const data = await response.json();
return data;
};
// 验证会员状态
const validateMembership = async (token) => {
const response = await fetch('/api/membership/validate', {
headers: {
'Authorization': `Bearer ${token}`
}
});
const data = await response.json();
return data;
};
cURL
# 登录
curl -X POST https://your-pages-project.pages.dev/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"password123"}'
# 验证会员状态
curl -X GET https://your-pages-project.pages.dev/api/membership/validate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"