快速入门
复制包含安装步骤和该插件完整 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-firebase-app-check`
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/firebase-app-check/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 工具中:
npx 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-firebase-app-check` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-firebase-app-checknpx cap sync导入
“导入”章节import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';快速入门
章节标题为“快速入门”import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
const result = await FirebaseAppCheck.getToken();// The result holds sensitive values: use it without logging it.示例:初始化
标题为“示例:初始化”的章节import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
await FirebaseAppCheck.initialize();示例:setTokenAutoRefreshEnabled
标题为“示例:setTokenAutoRefreshEnabled”的章节import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
await FirebaseAppCheck.setTokenAutoRefreshEnabled({ enabled: true });常见坑点
章节标题为“常见陷阱”- 监听器: 在页面卸载时移除句柄。
- 初始化一次: 在应用启动时运行 setup。
- 唯一可信来源:信任
src/definitions.ts在 GitHub 仓库中。
API 概览
章节标题:“API 概览”getToken
标题为“getToken”的章节获取当前的 App Check token。
import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
const result = await FirebaseAppCheck.getToken();// The result holds sensitive values: use it without logging it.initialize
“initialize” 章节为指定应用启用 App Check。 每个应用只能调用一次。
import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
await FirebaseAppCheck.initialize();setTokenAutoRefreshEnabled
标题为 “setTokenAutoRefreshEnabled” 的章节设置 App Check token 是否应自动刷新。
import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
await FirebaseAppCheck.setTokenAutoRefreshEnabled({ enabled: true });类型参考
“类型参考” 章节GetTokenOptions
“GetTokenOptions” 章节export interface GetTokenOptions { /** * If `true`, will always try to fetch a fresh token. * If `false`, will use a cached token if found in storage. * * @since 1.3.0 * @default false */ forceRefresh?: boolean;}GetTokenResult
“GetTokenResult” 章节export interface GetTokenResult { /** * The App Check token in JWT format. * * @since 1.3.0 */ token: string; /** * The timestamp after which the token will expire in milliseconds since epoch. * * Only available for Android and iOS. * * @since 1.3.0 */ expireTimeMillis?: number;}InitializeOptions
标题为 “InitializeOptions” 的章节export interface InitializeOptions { /** * If `true`, the debug provider is used. * * ⚠️ **Attention**: The debug provider allows access to your Firebase resources from unverified devices. * Don't use the debug provider in production builds of your app, and don't share your debug builds with untrusted parties. * * ⚠️ **Deprecated**: Use `debugToken` instead. This option will be removed in the next major version. * * Read more: https://firebase.google.com/docs/app-check/web/debug-provider * * @since 1.3.0 * @deprecated Use `debugToken` instead. This option will be removed in the next major version. * @default false */ debug?: boolean; /** * If `true`, the debug provider is used. * * On **Web**, you can also set a predefined debug token string instead of `true`. On Android and iOS, you have to use environment variables for this. * * ⚠️ **Attention**: The debug provider allows access to your Firebase resources from unverified devices. * Don't use the debug provider in production builds of your app, and don't share your debug builds with untrusted parties. * * @since 7.1.0 * @default false * @see https://firebase.google.com/docs/app-check/android/debug-provider#ci * @see https://firebase.google.com/docs/app-check/ios/debug-provider#ci * @see https://firebase.google.com/docs/app-check/web/debug-provider */ debugToken?: boolean | string; /** * If `true`, the SDK automatically refreshes App Check tokens as needed. * * @since 1.3.0 * @default false */ isTokenAutoRefreshEnabled?: boolean; /** * The provider to use for App Check. Must be an instance of * `ReCaptchaV3Provider`, `ReCaptchaEnterpriseProvider`, or `CustomProvider`. * * Only available for Web. * * @since 7.1.0 * @default ReCaptchaV3Provider * @see https://firebase.google.com/docs/app-check/web/custom-provider */ provider?: any; /** * The reCAPTCHA v3 site key (public key). This option is ignored when `provider` is set. * * Only available for Web. * * @deprecated Use `provider` instead. * @since 1.3.0 */ siteKey?: string;}SetTokenAutoRefreshEnabledOptions
标题为 “SetTokenAutoRefreshEnabledOptions” 的章节export interface SetTokenAutoRefreshEnabledOptions { /** * If `true`, the SDK automatically refreshes App Check tokens as needed. * This overrides any value set during initializeAppCheck(). * * @since 1.3.0 */ enabled: boolean;}TokenChangedListener
标题为 “TokenChangedListener” 的章节用于接收 token 变更事件的回调。
export type TokenChangedListener = (event: TokenChangedEvent) => void;GetPluginVersionResult
“GetPluginVersionResult” 章节export interface GetPluginVersionResult { /** * The semantic version of this plugin. * * @since 8.0.1 */ version: string;}TokenChangedEvent
标题为 “TokenChangedEvent” 的章节export interface TokenChangedEvent { /** * The App Check token in JWT format. * * @since 1.3.0 */ token: string;}单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节, 设备 有关 Devices 的实现细节,以及 Bundle 有关 Bundles 中的实现细节。