supabase-auth by nice-wolf-studio/claude-code-supabase-skills
npx skills add https://github.com/nice-wolf-studio/claude-code-supabase-skills --skill supabase-auth此技能通过 Supabase Auth API 提供身份验证和用户管理操作。支持邮箱/密码身份验证、会话管理、用户元数据和密码恢复。
必需的环境变量:
export SUPABASE_URL="https://your-project.supabase.co"
export SUPABASE_KEY="your-anon-or-service-role-key"
辅助脚本: 此技能使用共享的 Supabase API 辅助脚本。请确保已加载它:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
基础邮箱/密码注册:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
supabase_post "/auth/v1/signup" '{
"email": "user@example.com",
"password": "securepassword123"
}'
带用户元数据的注册:
supabase_post "/auth/v1/signup" '{
"email": "user@example.com",
"password": "securepassword123",
"data": {
"first_name": "John",
"last_name": "Doe",
"age": 30
}
}'
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
自动确认用户(需要服务角色密钥):
# 注意:为此操作使用带有 service_role 密钥的 SUPABASE_KEY
supabase_post "/auth/v1/signup" '{
"email": "user@example.com",
"password": "securepassword123",
"email_confirm": true
}'
邮箱/密码登录:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
response=$(supabase_post "/auth/v1/token?grant_type=password" '{
"email": "user@example.com",
"password": "securepassword123"
}')
# 提取访问令牌
access_token=$(echo "$response" | jq -r '.access_token')
refresh_token=$(echo "$response" | jq -r '.refresh_token')
echo "访问令牌: $access_token"
echo "刷新令牌: $refresh_token"
响应包含:
access_token - 用于身份验证请求的 JWT 令牌refresh_token - 用于在访问令牌过期时获取新令牌user - 包含 id、邮箱、元数据的用户对象expires_in - 令牌过期时间(秒)使用访问令牌检索用户信息:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
# 设置从登录获取的访问令牌
ACCESS_TOKEN="eyJhbGc..."
curl -s -X GET \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
更新用户元数据:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
ACCESS_TOKEN="eyJhbGc..."
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"data": {
"first_name": "Jane",
"avatar_url": "https://example.com/avatar.jpg"
}
}'
更新邮箱:
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"email": "newemail@example.com"
}'
更新密码:
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"password": "newsecurepassword123"
}'
退出登录用户(使刷新令牌失效):
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
ACCESS_TOKEN="eyJhbGc..."
curl -s -X POST \
"${SUPABASE_URL}/auth/v1/logout" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
使用刷新令牌获取新的访问令牌:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
REFRESH_TOKEN="your-refresh-token"
supabase_post "/auth/v1/token?grant_type=refresh_token" '{
"refresh_token": "'"${REFRESH_TOKEN}"'"
}'
发送密码重置邮件:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
supabase_post "/auth/v1/recover" '{
"email": "user@example.com"
}'
使用恢复令牌重置密码:
# 这通常通过邮件链接完成
# 恢复令牌来自邮件链接
RECOVERY_TOKEN="token-from-email"
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${RECOVERY_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"password": "newpassword123"
}'
重新发送邮箱验证邮件:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
supabase_post "/auth/v1/resend" '{
"type": "signup",
"email": "user@example.com"
}'
获取所有用户(需要服务角色密钥):
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
# 确保 SUPABASE_KEY 设置为 service_role 密钥
supabase_get "/auth/v1/admin/users"
分页用户列表:
# 使用分页获取用户
supabase_get "/auth/v1/admin/users?page=1&per_page=50"
检索特定用户(需要服务角色密钥):
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
USER_ID="user-uuid-here"
supabase_get "/auth/v1/admin/users/${USER_ID}"
无需邮箱确认创建用户:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
supabase_post "/auth/v1/admin/users" '{
"email": "admin-created@example.com",
"password": "securepassword123",
"email_confirm": true,
"user_metadata": {
"first_name": "Admin",
"last_name": "Created"
}
}'
以管理员身份更新用户:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
USER_ID="user-uuid-here"
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/admin/users/${USER_ID}" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}" \
-H "Content-Type: application/json" \
-d '{
"email": "updated@example.com",
"user_metadata": {
"role": "admin"
}
}'
删除用户账户:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
USER_ID="user-uuid-here"
supabase_delete "/auth/v1/admin/users/${USER_ID}"
#!/bin/bash
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
# 登录
response=$(supabase_post "/auth/v1/token?grant_type=password" '{
"email": "user@example.com",
"password": "password123"
}')
# 提取令牌
access_token=$(echo "$response" | jq -r '.access_token')
refresh_token=$(echo "$response" | jq -r '.refresh_token')
user_id=$(echo "$response" | jq -r '.user.id')
# 存储在环境变量或文件中供后续请求使用
export SUPABASE_ACCESS_TOKEN="$access_token"
export SUPABASE_REFRESH_TOKEN="$refresh_token"
export SUPABASE_USER_ID="$user_id"
echo "已登录用户: $user_id"
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
# 注意:这需要服务角色密钥和管理员端点
email="check@example.com"
users=$(supabase_get "/auth/v1/admin/users")
exists=$(echo "$users" | jq --arg email "$email" '.users[] | select(.email == $email)')
if [[ -n "$exists" ]]; then
echo "用户存在"
else
echo "用户不存在"
fi
# 令牌是 JWT - 您可以解码它们(需要 jq)
ACCESS_TOKEN="eyJhbGc..."
# 解码有效载荷(base64)
payload=$(echo "$ACCESS_TOKEN" | cut -d. -f2 | base64 -d 2>/dev/null)
echo "$payload" | jq '.'
# 检查过期时间
exp=$(echo "$payload" | jq -r '.exp')
now=$(date +%s)
if [[ $now -gt $exp ]]; then
echo "令牌已过期"
else
echo "令牌有效"
fi
常见错误响应:
| 状态码 | 错误 | 含义 |
|---|---|---|
| 400 | 无效的登录凭据 | 错误的邮箱或密码 |
| 400 | 用户已注册 | 邮箱已存在 |
| 401 | 无效的令牌 | 访问令牌已过期或无效 |
| 422 | 验证错误 | 无效的邮箱格式或弱密码 |
| 429 | 请求过多 | 超出速率限制 |
if response=$(supabase_post "/auth/v1/token?grant_type=password" '{...}' 2>&1); then
echo "登录成功"
access_token=$(echo "$response" | jq -r '.access_token')
else
echo "登录失败: $response"
exit 1
fi
典型流程:
令牌生命周期:
完整的 Supabase Auth API 文档:https://supabase.com/docs/guides/auth
每周安装量
145
代码仓库
GitHub 星标数
10
首次出现
2026年1月22日
安全审计
安装于
opencode119
codex118
gemini-cli116
cursor115
claude-code106
github-copilot106
This skill provides authentication and user management operations through the Supabase Auth API. Supports email/password authentication, session management, user metadata, and password recovery.
Required environment variables:
export SUPABASE_URL="https://your-project.supabase.co"
export SUPABASE_KEY="your-anon-or-service-role-key"
Helper script: This skill uses the shared Supabase API helper. Make sure to source it:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
Basic email/password signup:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
supabase_post "/auth/v1/signup" '{
"email": "user@example.com",
"password": "securepassword123"
}'
Signup with user metadata:
supabase_post "/auth/v1/signup" '{
"email": "user@example.com",
"password": "securepassword123",
"data": {
"first_name": "John",
"last_name": "Doe",
"age": 30
}
}'
Auto-confirm user (requires service role key):
# Note: Use SUPABASE_KEY with service_role key for this
supabase_post "/auth/v1/signup" '{
"email": "user@example.com",
"password": "securepassword123",
"email_confirm": true
}'
Email/password login:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
response=$(supabase_post "/auth/v1/token?grant_type=password" '{
"email": "user@example.com",
"password": "securepassword123"
}')
# Extract access token
access_token=$(echo "$response" | jq -r '.access_token')
refresh_token=$(echo "$response" | jq -r '.refresh_token')
echo "Access Token: $access_token"
echo "Refresh Token: $refresh_token"
Response includes:
access_token - JWT token for authenticated requestsrefresh_token - Token to get new access token when expireduser - User object with id, email, metadataexpires_in - Token expiration time in secondsRetrieve user info with access token:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
# Set your access token from login
ACCESS_TOKEN="eyJhbGc..."
curl -s -X GET \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
Update user metadata:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
ACCESS_TOKEN="eyJhbGc..."
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"data": {
"first_name": "Jane",
"avatar_url": "https://example.com/avatar.jpg"
}
}'
Update email:
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"email": "newemail@example.com"
}'
Update password:
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"password": "newsecurepassword123"
}'
Sign out user (invalidate refresh token):
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
ACCESS_TOKEN="eyJhbGc..."
curl -s -X POST \
"${SUPABASE_URL}/auth/v1/logout" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
Get new access token using refresh token:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
REFRESH_TOKEN="your-refresh-token"
supabase_post "/auth/v1/token?grant_type=refresh_token" '{
"refresh_token": "'"${REFRESH_TOKEN}"'"
}'
Send password reset email:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
supabase_post "/auth/v1/recover" '{
"email": "user@example.com"
}'
Reset password with recovery token:
# This is typically done through email link
# The recovery token comes from the email link
RECOVERY_TOKEN="token-from-email"
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/user" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${RECOVERY_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"password": "newpassword123"
}'
Resend email verification:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
supabase_post "/auth/v1/resend" '{
"type": "signup",
"email": "user@example.com"
}'
Get all users (requires service role key):
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
# Make sure SUPABASE_KEY is set to service_role key
supabase_get "/auth/v1/admin/users"
Paginated user list:
# Get users with pagination
supabase_get "/auth/v1/admin/users?page=1&per_page=50"
Retrieve specific user (requires service role key):
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
USER_ID="user-uuid-here"
supabase_get "/auth/v1/admin/users/${USER_ID}"
Create user without email confirmation:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
supabase_post "/auth/v1/admin/users" '{
"email": "admin-created@example.com",
"password": "securepassword123",
"email_confirm": true,
"user_metadata": {
"first_name": "Admin",
"last_name": "Created"
}
}'
Update user as admin:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
USER_ID="user-uuid-here"
curl -s -X PUT \
"${SUPABASE_URL}/auth/v1/admin/users/${USER_ID}" \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}" \
-H "Content-Type: application/json" \
-d '{
"email": "updated@example.com",
"user_metadata": {
"role": "admin"
}
}'
Delete user account:
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
USER_ID="user-uuid-here"
supabase_delete "/auth/v1/admin/users/${USER_ID}"
#!/bin/bash
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
# Login
response=$(supabase_post "/auth/v1/token?grant_type=password" '{
"email": "user@example.com",
"password": "password123"
}')
# Extract tokens
access_token=$(echo "$response" | jq -r '.access_token')
refresh_token=$(echo "$response" | jq -r '.refresh_token')
user_id=$(echo "$response" | jq -r '.user.id')
# Store in environment or file for subsequent requests
export SUPABASE_ACCESS_TOKEN="$access_token"
export SUPABASE_REFRESH_TOKEN="$refresh_token"
export SUPABASE_USER_ID="$user_id"
echo "Logged in as user: $user_id"
source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/supabase-api.sh"
# Note: This requires service role key and admin endpoint
email="check@example.com"
users=$(supabase_get "/auth/v1/admin/users")
exists=$(echo "$users" | jq --arg email "$email" '.users[] | select(.email == $email)')
if [[ -n "$exists" ]]; then
echo "User exists"
else
echo "User does not exist"
fi
# Tokens are JWTs - you can decode them (requires jq)
ACCESS_TOKEN="eyJhbGc..."
# Decode payload (base64)
payload=$(echo "$ACCESS_TOKEN" | cut -d. -f2 | base64 -d 2>/dev/null)
echo "$payload" | jq '.'
# Check expiration
exp=$(echo "$payload" | jq -r '.exp')
now=$(date +%s)
if [[ $now -gt $exp ]]; then
echo "Token expired"
else
echo "Token valid"
fi
Common error responses:
| Status | Error | Meaning |
|---|---|---|
| 400 | Invalid login credentials | Wrong email or password |
| 400 | User already registered | Email already exists |
| 401 | Invalid token | Access token expired or invalid |
| 422 | Validation error | Invalid email format or weak password |
| 429 | Too many requests | Rate limit exceeded |
if response=$(supabase_post "/auth/v1/token?grant_type=password" '{...}' 2>&1); then
echo "Login successful"
access_token=$(echo "$response" | jq -r '.access_token')
else
echo "Login failed: $response"
exit 1
fi
Typical flow:
Token lifespan:
Full Supabase Auth API documentation: https://supabase.com/docs/guides/auth
Weekly Installs
145
Repository
GitHub Stars
10
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykPass
Installed on
opencode119
codex118
gemini-cli116
cursor115
claude-code106
github-copilot106
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
152,900 周安装