开始
复制一个包含安装步骤和此插件的完整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 工具中,使用以下命令:
bunx 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.如果您更喜欢手动设置,请运行以下命令安装插件,并按照以下平台特定的说明进行操作:
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'});示例:使用密码登录
示例:使用密码登录import { CapacitorSupabase } from '@capgo/capacitor-supabase';
const { session, user } = await CapacitorSupabase.signInWithPassword({ email: 'user@example.com', password: 'password123'});console.log('JWT:', session?.accessToken);示例:注册
示例:注册import { CapacitorSupabase } from '@capgo/capacitor-supabase';
const { session, user } = await CapacitorSupabase.signUp({ email: 'newuser@example.com', password: 'password123', data: { name: 'John Doe' }});常见问题
常见问题- 监听器:卸载屏幕时移除句柄。
- 初始化一次:在应用程序引导期间运行设置。
- 真实来源:相信
src/definitions.ts在GitHub仓库。
Android最低SDK
Section titled “Android Minimum SDK”Android 实现需要 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 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 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);- 使用此插件进行身份验证和会话管理。
- 将本地 JWT 传递给 JavaScript 客户端以获得 Supabase 面板的其余功能。
@supabase/supabase-js. - 继续从 Getting Started
继续从 Getting Started
Keep Realtime, Storage, Edge Functions, and advanced querying in如果您正在使用 开始使用 为了规划原生插件工作,连接它与 Capgo 插件目录 在 Capgo 插件目录 中的产品工作流程 Capacitor Capgo 由 Capgo 提供的插件 为 Capacitor 插件的实现细节提供 Capgo 添加或更新插件 在添加或更新插件 中的实现细节 Ionic 企业插件替代品 在 Ionic 企业插件替代品 中的产品工作流程 Capgo 原生构建 为 Capgo 原生构建工作流程。