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.
安装
安装您可以使用我们的 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.如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:
npm install @capgo/capacitor-supabasenpx cap sync安卓最低版本 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 Pair Native Auth
Pair Native Auth With supabase-jsimport { 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 Database Helpers
Native Database Helpersconst { 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);Recommended Usage
Recommended Usage- 使用此插件进行身份验证和会话管理。
- 保留实时、存储、边缘功能和高级查询功能。
@supabase/supabase-js. - 在 JavaScript 客户端中传递 native JWT 时,始终使用 Supabase 面板的其余部分。
继续从 Getting Started
继续从 Getting Started 的部分如果您正在使用 Getting Started 来规划原生插件工作,连接它与 Capgo 插件目录 为产品工作流程在 Capgo 插件目录中 Capacitor 由 Capgo 为 Capacitor 由 Capgo 的实现细节 添加或更新插件 为添加或更新插件的实现细节 Ionic 企业插件替代方案 为 Ionic Enterprise Plugin Alternatives 的产品工作流程,和 Capgo 原生构建 为 Capgo 原生构建 的产品工作流程,。