开始
复制一个包含安装步骤和此插件的完整 Markdown 指南的设置提示。
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 能力添加到您的 AI 工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-supabase` plugin in my project.如果您prefer手动设置,安装插件并运行以下命令并遵循以下平台特定说明:
npm install @capgo/capacitor-supabasenpx cap syncAndroid 最低版本 SDK
Android 最低版本 SDKAndroid 实现需要 Android 8.0 或更高版本。设置 minSdkVersion = 26 在 android/variables.gradle.
初始化客户端
标题:初始化客户端import { CapacitorSupabase } from '@capgo/capacitor-supabase';
await CapacitorSupabase.initialize({ supabaseUrl: 'https://your-project.supabase.co', supabaseKey: 'your-anon-key',});登录并访问 JWT
标题:登录并访问 JWTconst { session, user } = await CapacitorSupabase.signInWithPassword({ email: 'user@example.com', password: 'password123',});
console.log('User', user?.id);console.log('JWT available', Boolean(session?.accessToken));监听身份验证变化
监听身份验证变化const listener = await CapacitorSupabase.addListener('authStateChange', ({ event, session }) => { console.log('Auth event', event); console.log('Current JWT available', Boolean(session?.accessToken));});
await listener.remove();与 supabase-js 配对本地认证
Section titled “与 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);本地数据库辅助工具
Section titled “本地数据库辅助工具”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);- 使用此插件进行身份验证和会话管理。
- 保留实时数据、存储、边缘功能和高级查询功能
@supabase/supabase-js. - 每当您需要使用 Supabase 的其余功能时,请将原生 JWT 传递到 JavaScript 客户端。
继续 Getting Started
继续 Getting Started如果您正在使用 开始使用 与 Capgo 插件目录 为产品工作流程在 Capgo 插件目录 Capacitor 由 Capgo 提供的插件 为 Capacitor 插件的实现细节了解 Capgo 添加或更新插件 为实现细节在添加或更新插件 Ionic 企业插件替代品 为 Ionic 企业插件替代品中的产品工作流程 Capgo 原生构建 为 Capgo 原生构建中的产品工作流程