Getting Started
复制一个设置提示,包含安装步骤和该插件的完整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.
安装
标题为“安装”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 配对的原生认证
标题:与 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);原生数据库助手
标题:原生数据库助手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. - 在 JavaScript 客户端中传递原生 JWT 时,始终获得 Supabase 面板的其余功能。
继续从 Getting Started
《从 Getting Started 开始继续》如果您正在使用 Getting Started 规划原生插件工作时,将其与 Capgo 插件目录 Capgo 插件目录中的产品工作流 Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, __CAPGO_KEEP_0__ 插件 __CAPGO_KEEP_1__ 插件的实现细节 添加或更新插件的实现细节,请参见《添加或更新插件》,《Ionic Enterprise Plugin Alternatives》中的产品工作流,以及 Capgo 原生构建 为产品工作流程在 Capgo 原生构建.