快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-supabase`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/supabase/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-supabase` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-supabasebunx cap sync快速入门
章节标题为“快速入门”import { CapacitorSupabase } from '@capgo/capacitor-supabase';
await CapacitorSupabase.initialize({ supabaseUrl: 'https://xyzcompany.supabase.co', supabaseKey: 'your-anon-key'});示例:signInWithPassword
标题为 “Example: signInWithPassword” 的章节import { CapacitorSupabase } from '@capgo/capacitor-supabase';
const { session, user } = await CapacitorSupabase.signInWithPassword({ email: 'user@example.com', password: 'password123'});console.log('JWT:', session?.accessToken);示例:signUp
标题为 “Example: signUp” 的章节import { CapacitorSupabase } from '@capgo/capacitor-supabase';
const { session, user } = await CapacitorSupabase.signUp({ email: 'newuser@example.com', password: 'password123', data: { name: 'John Doe' }});常见坑点
章节标题为“常见陷阱”- 监听器: 在页面卸载时移除句柄。
- 初始化一次: 在应用启动时运行 setup。
- 唯一可信来源:信任
src/definitions.ts在 GitHub 仓库中。
Android 最低 SDK 版本
标题为“Android 最低 SDK”Android 端实现需要 Android 8.0 或更高版本。设置 minSdkVersion = 26 中的 android/variables.gradle.
初始化客户端
标题为“初始化 Client”import { CapacitorSupabase } from '@capgo/capacitor-supabase';
await CapacitorSupabase.initialize({ supabaseUrl: 'https://your-project.supabase.co', supabaseKey: 'your-anon-key',});登录并获取 JWT
标题为“登录并获取 JWT”const { session, user } = await CapacitorSupabase.signInWithPassword({ email: 'user@example.com', password: 'password123',});
console.log('User', user?.id);console.log('JWT available', Boolean(session?.accessToken));监听 Auth 状态变化
“监听 Auth 变化”章节const listener = await CapacitorSupabase.addListener('authStateChange', ({ event, session }) => { console.log('Auth event', event); console.log('Current JWT available', Boolean(session?.accessToken));});
await listener.remove();将 Native Auth 与 supabase-js 结合使用
“将 Native Auth 与 supabase-js 结合使用”章节import { createClient } from '@supabase/supabase-js';
const { session } = await CapacitorSupabase.getSession();
const supabase = createClient('https://your-project.supabase.co', 'your-anon-key', { global: { headers: { Authorization: `Bearer ${session?.accessToken}`, }, },});
const { data } = await supabase.from('table').select('*');console.log(data);Native 数据库辅助函数
“原生数据库辅助函数”章节const { data, error } = await CapacitorSupabase.select({ table: 'users', columns: 'id, name, email', filter: { active: true }, limit: 10, orderBy: 'created_at', ascending: false,});
console.log(data, error);推荐用法
“推荐用法”章节- 使用此插件进行身份验证和会话管理。
- 将 Realtime、Storage、Edge Functions 及高级查询功能集成到
@supabase/supabase-js. - 当需要使用 Supabase 的其他功能时,请将原生 JWT 传递给 JavaScript client。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划原生插件工作,请将其与 Capgo 插件目录 查看 Capgo 插件目录中的产品工作流, Capgo 提供的 Capacitor 插件 查看由 Capgo 提供的 Capacitor 插件中的实现细节, 添加或更新插件 查看添加或更新插件中的实现细节, Ionic Enterprise 插件替代方案 查看 Ionic Enterprise 插件替代方案中的产品工作流,以及 Capgo Native Build 查看 Capgo Native Builds 中的产品工作流。