[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79GP3BDB7WMRVDQXATTSX41":3,"skill-same:01M79GP3BDB7WMRVDQXATTSX41":51},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M79GP3BDB7WMRVDQXATTSX41","auth-web-cloudbase",null,"CloudBase Web Authentication Quick Guide for frontend integration after auth-tool has already been checked. Provides concise and practical Web authentication solutions with multiple login methods and complete user management.","infometa\u002Fworkbuddyskills","infometa","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F109397516?v=4","01M79FS3XQK361MJFWQ2GFK95C","01M79FS3YPWKZYW9EPAAP2BFBJ",447,"MIT","https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fconnectors\u002Fcloudbase\u002Fskills\u002Freferences\u002Fauth-web-cloudbase\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: auth-web-cloudbase\ndescription: CloudBase Web Authentication Quick Guide for frontend integration after auth-tool has already been checked. Provides concise and practical Web authentication solutions with multiple login methods and complete user management.\nversion: 2.36.2\nlicense: MIT\nalwaysApply: false\n---\n\n## Sibling skills (local only)\n\nSibling CloudBase skills ship beside this skill. Use local relative paths such as `..\u002Fauth-tool-cloudbase\u002FSKILL.md`.\n\nIf a referenced sibling skill file is missing from this environment, ask the user to install the full CloudBase plugin (or the missing skill). Do **not** HTTP-fetch remote skill or protocol markdown into the agent context.\n\n## Activation Contract\n\n### Use this first when\n\n- The task is a CloudBase Web login, registration, session, or user profile flow built with `@cloudbase\u002Fjs-sdk` and the auth provider setup has already been checked.\n\n### Read before writing code if\n\n- The user needs a login page, auth modal, session handling, or protected Web route. Read `auth-tool-cloudbase` first to ensure providers are enabled, then return here for frontend integration.\n\n### Then also read\n\n- `..\u002Fauth-tool-cloudbase\u002FSKILL.md` for provider setup\n- `..\u002Fweb-development\u002FSKILL.md` for Web project structure and deployment\n\n### Do not start here first when\n\n- The request is a Web auth flow but provider configuration has not been verified yet.\n- In that case, activate `auth-tool-cloudbase` before `auth-web-cloudbase`.\n\n### Do NOT use for\n\n- Mini program auth, native App auth, or server-side auth setup.\n\n### Common mistakes \u002F gotchas\n\n- Skipping publishable key and provider checks.\n- Replacing built-in Web auth with cloud function login logic.\n- Reusing this flow in Flutter, React Native, or native iOS\u002FAndroid code.\n- Creating a detached helper file with `auth.signUp` \u002F `verifyOtp` but never wiring it into the existing form handlers, so the actual button clicks still do nothing.\n- Using `signInWithEmailAndPassword` or `signUpWithEmailAndPassword` for username-style accounts such as `admin` and `editor`.\n- Keeping the login or register account input as `type=\"email\"` when the task explicitly says the account identifier is a plain username string.\n- Starting implementation before calling `queryAppAuth(action=\"getLoginConfig\")` and enabling `usernamePassword` when it is still off.\n- **Writing `auth.signInWithPassword(...)` or `auth.signUp(...)` code without first confirming the provider is enabled via MCP.** Before writing any sign-in or sign-up code in the browser, call `queryAppAuth(action=\"listProviders\")` to verify the target provider (e.g. `email`, `phone`, `usernamePassword`) has `On: \"TRUE\"`. For email-based sign-up (`auth.signUp({ email, password })`), additionally confirm SMTP is configured — otherwise the provider may throw `\"provider email not found\"` or similar errors. For username\u002Fpassword login, use `auth.signInWithPassword({ username, password })`; registration is best done through the management API (`manageAppAuth(action=\"createUser\")`) or by confirming email provider readiness first.\n- **Treating `auth.getUser()` or deprecated `auth.getLoginState()` as proof of real login.** When the SDK is initialized with `accessKey`, the deprecated `getLoginState()` may still return an object with a valid `uid` even without any login — causing route guards that check `!!loginState` or `!!uid` to incorrectly pass. That misleading `uid` is **not** a gateway-authenticated session. Use `auth.getSession()` instead: it returns `data.session === undefined` when no real login has occurred. Only `!!data.session` from `getSession()` is a reliable authentication check.\n- **Assuming publishable `accessKey` alone is enough for NoSQL CRUD.** NoSQL `app.database()` `get` \u002F `add` \u002F `update` \u002F `watch` requires a gateway-authenticated **session**: use a real login (password \u002F OTP \u002F OAuth). Anonymous login is a demo-only escape hatch for explicitly-public, non-user data — it is disabled by default, denied AI model permissions, and must never stand in for real auth in user-scoped apps. Skipping any login yields **gateway 401**. `checkLogin()` \u002F `getSession()` alone do **not** create a usable write session.\n- **Copying old CloudBase auth snippets from training data.** Do not use `auth.getLoginState()`, `auth.hasLoginState()`, `auth.getCurrentUser()`, or `auth.toDefaultLoginPage()` as the default Web flow. Use the Web SDK v3 auth methods in this file and provider readiness from `auth-tool-cloudbase`.\n- **Calling a standalone `auth.verifyOtp({ token })` for OTP login.** CloudBase Web SDK v3 returns `verifyOtp` as a callback on the `signInWithOtp` \u002F `signUp` result: send the code first, keep the returned `data`, then call `data.verifyOtp({ token })`. A standalone `auth.verifyOtp({ token })` without `messageId` fails with `\"messageId is required\"` — seeing that error means the callback form was skipped. See `references\u002Fextended-guide.md` for the full send → save callback → verify flow.\n  \n  Note: anonymous login is **disabled by default** for new environments and inactive existing environments. Do not enable it to work around permission errors — enable via `auth-tool-cloudbase` only when the app explicitly serves public non-user data (e.g. NoSQL read-only demos). Always use `auth.getSession()` for auth guards.\n\n## Overview\n\n**Prerequisites**: CloudBase environment ID (`env`)\n**Prerequisites**: CloudBase environment Region (`region`)\n\n---\n\n## Core Capabilities\n\n**Use Case**: Web frontend projects using `@cloudbase\u002Fjs-sdk@latest` for user authentication  \n**Key Benefits**: **Supabase-compatible Auth API** — all methods return `{ data, error }`, supports phone, email, anonymous (disabled by default), username\u002Fpassword, OAuth, and third-party login methods\n\n> 📌 **Supabase API Compatibility**: CloudBase Web SDK v3 auth module is designed with Supabase-like API ergonomics. If you are familiar with `supabase-js` auth patterns, the same mental model applies:\n> - All methods return `Promise\u003C{ data, error }>` — always check `error` first\n> - `signInWithPassword`, `signInWithOtp`, `signUp`, `signOut`, `getSession`, `getUser` follow the same naming as Supabase\n> - `onAuthStateChange(callback)` provides reactive auth state observation (events: `INITIAL_SESSION`, `SIGNED_IN`, `SIGNED_OUT`, `TOKEN_REFRESHED`, `USER_UPDATED`, `PASSWORD_RECOVERY`, `BIND_IDENTITY`)\n> - Session management via `getSession()` \u002F `refreshSession()` \u002F `setSession()` mirrors Supabase patterns\n> \n> **Key differences from Supabase**:\n> - **OTP verification**: Supabase uses a standalone `auth.verifyOtp({ phone, token, type })` call; CloudBase returns `verifyOtp` as a callback on `data` — call `data.verifyOtp({ token })` from the `signInWithOtp` \u002F `signUp` result\n> - **`accessKey`** replaces Supabase's `anonKey`; environment uses `env` + `region` instead of Supabase's `url`\n> - **`signInWithIdToken`** for direct third-party token login (similar to Supabase's same-named method)\n\nUse npm installation for modern Web projects. In React, Vue, Vite, and other bundler-based apps, install and import `@cloudbase\u002Fjs-sdk` from the project dependencies instead of using a CDN script.\n\n## Prerequisites\n\n- Automatically use `auth-tool-cloudbase` to check app-side auth readiness via `queryAppAuth` \u002F `manageAppAuth`, then get the `publishable key` and configure login methods.\n- **Publishable key readiness (do not skip):** call `queryAppAuth(action=\"getPublishableKey\")`. If it is empty, call `manageAppAuth(action=\"ensurePublishableKey\")` first — new environments may not have one provisioned, and skipping this step leaves the frontend without a data-plane credential, surfacing later as gateway auth failures instead of an obvious missing-key error.\n- **Persist the key, don't hoard it in conversation:** after retrieval, write the publishable key to `.env.local` as `VITE_PUBLISHABLE_KEY` (create the file if missing) and read it in client code via `import.meta.env.VITE_PUBLISHABLE_KEY`. Never hardcode the key into source files, and never ask the user to fetch it from the console — fall back to the console link below only if both MCP calls fail.\n- If `auth-tool-cloudbase` failed, let user go to `https:\u002F\u002Ftcb.cloud.tencent.com\u002Fdev?envId={env}#\u002Fenv\u002Fapikey` to get `publishable key` and `https:\u002F\u002Ftcb.cloud.tencent.com\u002Fdev?envId={env}#\u002Fidentity\u002Flogin-manage` to set up login methods\n\n### Parameter map\n\n- For username-style identifiers, the required precondition is `loginMethods.usernamePassword === true` from `queryAppAuth(action=\"getLoginConfig\")`. If it is false, enable it with `manageAppAuth(action=\"patchLoginStrategy\", patch={ usernamePassword: true })` before wiring frontend auth code.\n- If the conversation only provides an environment alias, nickname, or other shorthand, resolve it with `queryEnv(action=\"list\", alias=..., aliasExact=true)` first and use the returned canonical full `EnvId` for SDK init, console links, and generated config. Do not pass alias-like short forms directly into `cloudbase.init({ env })`.\n- Treat CloudBase Web Auth as **Supabase-like**, not “every `supabase-js` auth example is valid unchanged”\n- When `queryAppAuth` \u002F `manageAppAuth` returns `sdkStyle: \"supabase-like\"` and `sdkHints`, follow those method and parameter hints first\n- `auth.signInWithOtp({ phone })` and `auth.signUp({ phone })` use the phone number in a `phone` field, not `phone_number`\n- `auth.signInWithOtp({ email })` and `auth.signUp({ email })` use `email`\n- `auth.signInWithPassword({ username, password })` is the canonical Web login path for username\u002Fpassword accounts\n- Treat direct Web `auth.signUp({ username, password })` as conditional. Verify `sdkHints` and the installed SDK first; some versions only support `signUp` for OTP\u002Fprovider-token flows and will not create username\u002Fpassword users.\n- If the task gives accounts like `admin`, `editor`, or another plain string without `@`, treat it as a username-style identifier rather than an email address\n- `data.verifyOtp({ token })` — the `verifyOtp` callback on the `signInWithOtp` \u002F `signUp` result `data` — expects the SMS or email code in `token`; do not invent a standalone `auth.verifyOtp({ token })` call, which additionally requires `messageId`\n- `accessKey` is the publishable key from `queryAppAuth` \u002F `manageAppAuth` via `auth-tool-cloudbase`, not a secret key\n- **`accessKey` alone does not create a gateway-authenticated session.** Publishable `accessKey` initializes the SDK; it does **not** replace a login for NoSQL CRUD. Any `app.database()` `get` \u002F `add` \u002F `update` \u002F `watch` needs a session — prefer a real login (password \u002F OTP \u002F OAuth); `signInAnonymously()` only for explicitly-public demo data (disabled by default, denied AI model permissions). Otherwise the gateway returns **401**. Separately: the deprecated `auth.getLoginState()` may still return a misleading `uid` without login; use `auth.getSession()` for route guards (`data.session === undefined` when not logged in). `checkLogin()` \u002F `getSession()` alone do **not** create a usable write session.\n- Never set `accessKey` to `envId`, a username, or any placeholder string. If you do not have a real Publishable Key yet, do not fabricate one.\n- If the task mentions provider setup, stop and read `auth-tool-cloudbase` before writing frontend code\n\n## Quick Start\n\nSDK init reference: [docs.cloudbase.net\u002Fapi-reference\u002Fwebv3\u002Finitialization.md](https:\u002F\u002Fdocs.cloudbase.net\u002Fapi-reference\u002Fwebv3\u002Finitialization.md)（URL 加 `.md` 可取 raw markdown 原文）\n\n```js\n\u002F\u002F npm install @cloudbase\u002Fjs-sdk\nimport cloudbase from '@cloudbase\u002Fjs-sdk'\n\nconst app = cloudbase.init({\n  env: 'your-full-env-id', \u002F\u002F Canonical full CloudBase environment ID resolved from queryEnv or the console, not an alias or shorthand\n  region: 'ap-shanghai',  \u002F\u002F CloudBase environment Region, default 'ap-shanghai'\n  accessKey: 'publishable key', \u002F\u002F required, get from auth-tool-cloudbase\n  \u002F\u002F ⚠️ accessKey alone ≠ a login session. NoSQL CRUD needs a session —\n  \u002F\u002F real login preferred; signInAnonymously() only for public demo data.\n  \u002F\u002F Use auth.getSession() for route guards; deprecated getLoginState()\n  \u002F\u002F may return a misleading uid without a real session.\n  auth: { detectSessionInUrl: true }, \u002F\u002F required\n})\n\nconst auth = app.auth\n\n\u002F\u002F NoSQL app.database() CRUD requires a session (js-sdk 3.x + publishable key).\n\u002F\u002F Real login (see cookbook). Anonymous, only for public non-user demos:\n\u002F\u002F const { error } = await auth.signInAnonymously()\n\u002F\u002F if (error) throw error\n```\n\nIf the current task has not retrieved a real Publishable Key, omit `accessKey` instead of inventing one. A wrong `accessKey` can break auth-state checks and protected-route behavior.\n\n## Auth code cookbook (official v3 API — copy these, do not re-derive from .d.ts)\n\nEvery method returns the unified shape `{ data, error }` — branch on `error` first and surface `error.message`. The auth API is identical in traditional and PG environments. Source: [official auth docs](https:\u002F\u002Fdocs.cloudbase.net\u002Fapi-reference\u002Fwebv3\u002Fauthentication.md)（raw markdown, cross-check snippets there when in doubt）.\n\n**Default auth UI contract:** when the user asks for 登录\u002F注册\u002F账号体系\u002Fuser system without restricting the method, the login page must make ALL of these reachable (tabs or separate forms): password sign-in, OTP sign-in, verified sign-up (code + password), and forgot-password (whenever password sign-in exists). Never ship OTP-only or password-only UI unless explicitly asked. Never reveal whether an identifier is already registered in user-facing copy — route existing users to login with neutral wording.\n\n**Password sign-in** (username-style or email identifiers both go here):\n\n```js\nconst { data, error } = await auth.signInWithPassword({ username, password })\n\u002F\u002F email accounts: auth.signInWithPassword({ email, password })\nif (error) { \u002F* show error.message *\u002F } else { \u002F* data.user *\u002F }\n```\n\n**Anonymous sign-in — demo-only, not a default.** NoSQL `app.database()` CRUD needs some session (PG anon reads work with accessKey alone). Prefer a real login; reach for anonymous ONLY when the app explicitly serves public non-user data and the user accepts the trade-off — it is disabled by default, denied AI model permissions, and its `uid` must never own user-scoped rows:\n\n```js\nconst { error } = await auth.signInAnonymously()\n```\n\n**Registration — verification code is MANDATORY.** There is no password-only signup: `signUp` itself sends a code, and `data.verifyOtp` must complete it. Smart flow: existing identifier → plain login; new identifier → register + auto-login. Phone\u002FSMS is 上海地域 only — prefer email:\n\n```js\nconst { data, error } = await auth.signUp({ email, password }) \u002F\u002F or { phone, password }\nif (error) throw error\n\u002F\u002F user types the code from their inbox...\nconst { data: login, error: verifyErr } = await data.verifyOtp({ token: code })\n\u002F\u002F login.user \u002F login.session — signed in on both paths\n```\n\n**OTP sign-in (no password)** — same shape as `signUp`, auto-creates the user by default (`shouldCreateUser: false` to refuse unknown users). Requires 邮箱\u002F短信验证码登录 enabled in console → 身份认证\u002F登录方式:\n\n```js\nconst { data, error } = await auth.signInWithOtp({ email }) \u002F\u002F or { phone }\nconst { data: login, error: verifyErr } = await data.verifyOtp({ token: code })\n```\n\n**Forgot password** — email code → set new password → auto sign-in (emits `PASSWORD_RECOVERY`):\n\n```js\nconst { data, error } = await auth.resetPasswordForEmail(email)\nif (error) throw error\nconst { data: login, error: resetErr } = await data.updateUser({ nonce: code, password: newPassword })\n```\n\n**OTP closure vs standalone `verifyOtp` — do not mix.** The `data.verifyOtp` returned by `signUp` \u002F `signInWithOtp` \u002F `resetPasswordForEmail` has the message ID bound (pass only `{ token }`). The standalone `auth.verifyOtp(...)` requires `messageId` and **only logs in — it never registers**. Always use the returned closure.\n\n**Session check \u002F route guard** — always `getSession()`, never the deprecated `getLoginState()`:\n\n```js\nconst { data } = await auth.getSession()\nconst session = data?.session \u002F\u002F undefined === not logged in\n```\n\n**Auth state listener** (wire this once at app bootstrap):\n\n```js\nauth.onAuthStateChange((event, session) => {\n  \u002F\u002F event: INITIAL_SESSION | SIGNED_IN | SIGNED_OUT | PASSWORD_RECOVERY\n  \u002F\u002F        | TOKEN_REFRESHED | USER_UPDATED | BIND_IDENTITY\n})\n```\n\n**Sign out:**\n\n```js\nconst { error } = await auth.signOut()\n```\n\n**Mandatory auth gate before user-scoped data.** Before reading\u002Fwriting user-owned PG rows or Storage objects, check the session and show login when absent — never \"fix\" data errors by silently calling `signInAnonymously`:\n\n```js\nconst { data } = await auth.getSession()\nif (!data?.session) { navigate('\u002Flogin'); return }\n```\n\n**Completion Bar** — before calling the auth task done, the generated source must have ALL of:\n\n- [ ] `signInWithPassword` (when password login is part of the UI)\n- [ ] a verification-code path: `signUp` + `data.verifyOtp` and\u002For `signInWithOtp`\n- [ ] auth gate before user-scoped DB\u002FStorage calls (rule above)\n- [ ] `onAuthStateChange` wired at bootstrap (route guard reacts to `SIGNED_OUT`)\n- [ ] errors surfaced from `error.message`, no invented error text\n- [ ] NO `signInAnonymously` as a fallback for permission errors, no mock\u002FlocalStorage sessions\n\n---\n\n## Extended guide\n\nFor detailed scenarios, examples, and patterns, read [extended-guide.md](references\u002Fextended-guide.md).\n\n## Reference index\n\nAll packaged reference files (required for skill lint reachability):\n\n- [extended-guide.md](references\u002Fextended-guide.md)\n","## Sibling skills (local only)\n\nSibling CloudBase skills ship beside this skill. Use local relative paths such as `..\u002Fauth-tool-cloudbase\u002FSKILL.md`.\n\nIf a referenced sibling skill file is missing from this environment, ask the user to install the full CloudBase plugin (or the missing skill). Do **not** HTTP-fetch remote skill or protocol markdown into the agent context.\n\n## Activation Contract\n\n### Use this first when\n\n- The task is a CloudBase Web login, registration, session, or user profile flow built with `@cloudbase\u002Fjs-sdk` and the auth provider setup has already been checked.\n\n### Read before writing code if\n\n- The user needs a login page, auth modal, session handling, or protected Web route. Read `auth-tool-cloudbase` first to ensure providers are enabled, then return here for frontend integration.\n\n### Then also read\n\n- `..\u002Fauth-tool-cloudbase\u002FSKILL.md` for provider setup\n- `..\u002Fweb-development\u002FSKILL.md` for Web project structure and deployment\n\n### Do not start here first when\n\n- The request is a Web auth flow but provider configuration has not been verified yet.\n- In that case, activate `auth-tool-cloudbase` before `auth-web-cloudbase`.\n\n### Do NOT use for\n\n- Mini program auth, native App auth, or server-side auth setup.\n\n### Common mistakes \u002F gotchas\n\n- Skipping publishable key and provider checks.\n- Replacing built-in Web auth with cloud function login logic.\n- Reusing this flow in Flutter, React Native, or native iOS\u002FAndroid code.\n- Creating a detached helper file with `auth.signUp` \u002F `verifyOtp` but never wiring it into the existing form handlers, so the actual button clicks still do nothing.\n- Using `signInWithEmailAndPassword` or `signUpWithEmailAndPassword` for username-style accounts such as `admin` and `editor`.\n- Keeping the login or register account input as `type=\"email\"` when the task explicitly says the account identifier is a plain username string.\n- Starting implementation before calling `queryAppAuth(action=\"getLoginConfig\")` and enabling `usernamePassword` when it is still off.\n- **Writing `auth.signInWithPassword(...)` or `auth.signUp(...)` code without first confirming the provider is enabled via MCP.** Before writing any sign-in or sign-up code in the browser, call `queryAppAuth(action=\"listProviders\")` to verify the target provider (e.g. `email`, `phone`, `usernamePassword`) has `On: \"TRUE\"`. For email-based sign-up (`auth.signUp({ email, password })`), additionally confirm SMTP is configured — otherwise the provider may throw `\"provider email not found\"` or similar errors. For username\u002Fpassword login, use `auth.signInWithPassword({ username, password })`; registration is best done through the management API (`manageAppAuth(action=\"createUser\")`) or by confirming email provider readiness first.\n- **Treating `auth.getUser()` or deprecated `auth.getLoginState()` as proof of real login.** When the SDK is initialized with `accessKey`, the deprecated `getLoginState()` may still return an object with a valid `uid` even without any login — causing route guards that check `!!loginState` or `!!uid` to incorrectly pass. That misleading `uid` is **not** a gateway-authenticated session. Use `auth.getSession()` instead: it returns `data.session === undefined` when no real login has occurred. Only `!!data.session` from `getSession()` is a reliable authentication check.\n- **Assuming publishable `accessKey` alone is enough for NoSQL CRUD.** NoSQL `app.database()` `get` \u002F `add` \u002F `update` \u002F `watch` requires a gateway-authenticated **session**: use a real login (password \u002F OTP \u002F OAuth). Anonymous login is a demo-only escape hatch for explicitly-public, non-user data — it is disabled by default, denied AI model permissions, and must never stand in for real auth in user-scoped apps. Skipping any login yields **gateway 401**. `checkLogin()` \u002F `getSession()` alone do **not** create a usable write session.\n- **Copying old CloudBase auth snippets from training data.** Do not use `auth.getLoginState()`, `auth.hasLoginState()`, `auth.getCurrentUser()`, or `auth.toDefaultLoginPage()` as the default Web flow. Use the Web SDK v3 auth methods in this file and provider readiness from `auth-tool-cloudbase`.\n- **Calling a standalone `auth.verifyOtp({ token })` for OTP login.** CloudBase Web SDK v3 returns `verifyOtp` as a callback on the `signInWithOtp` \u002F `signUp` result: send the code first, keep the returned `data`, then call `data.verifyOtp({ token })`. A standalone `auth.verifyOtp({ token })` without `messageId` fails with `\"messageId is required\"` — seeing that error means the callback form was skipped. See `references\u002Fextended-guide.md` for the full send → save callback → verify flow.\n  \n  Note: anonymous login is **disabled by default** for new environments and inactive existing environments. Do not enable it to work around permission errors — enable via `auth-tool-cloudbase` only when the app explicitly serves public non-user data (e.g. NoSQL read-only demos). Always use `auth.getSession()` for auth guards.\n\n## Overview\n\n**Prerequisites**: CloudBase environment ID (`env`)\n**Prerequisites**: CloudBase environment Region (`region`)\n\n---\n\n## Core Capabilities\n\n**Use Case**: Web frontend projects using `@cloudbase\u002Fjs-sdk@latest` for user authentication  \n**Key Benefits**: **Supabase-compatible Auth API** — all methods return `{ data, error }`, supports phone, email, anonymous (disabled by default), username\u002Fpassword, OAuth, and third-party login methods\n\n> 📌 **Supabase API Compatibility**: CloudBase Web SDK v3 auth module is designed with Supabase-like API ergonomics. If you are familiar with `supabase-js` auth patterns, the same mental model applies:\n> - All methods return `Promise\u003C{ data, error }>` — always check `error` first\n> - `signInWithPassword`, `signInWithOtp`, `signUp`, `signOut`, `getSession`, `getUser` follow the same naming as Supabase\n> - `onAuthStateChange(callback)` provides reactive auth state observation (events: `INITIAL_SESSION`, `SIGNED_IN`, `SIGNED_OUT`, `TOKEN_REFRESHED`, `USER_UPDATED`, `PASSWORD_RECOVERY`, `BIND_IDENTITY`)\n> - Session management via `getSession()` \u002F `refreshSession()` \u002F `setSession()` mirrors Supabase patterns\n> \n> **Key differences from Supabase**:\n> - **OTP verification**: Supabase uses a standalone `auth.verifyOtp({ phone, token, type })` call; CloudBase returns `verifyOtp` as a callback on `data` — call `data.verifyOtp({ token })` from the `signInWithOtp` \u002F `signUp` result\n> - **`accessKey`** replaces Supabase's `anonKey`; environment uses `env` + `region` instead of Supabase's `url`\n> - **`signInWithIdToken`** for direct third-party token login (similar to Supabase's same-named method)\n\nUse npm installation for modern Web projects. In React, Vue, Vite, and other bundler-based apps, install and import `@cloudbase\u002Fjs-sdk` from the project dependencies instead of using a CDN script.\n\n## Prerequisites\n\n- Automatically use `auth-tool-cloudbase` to check app-side auth readiness via `queryAppAuth` \u002F `manageAppAuth`, then get the `publishable key` and configure login methods.\n- **Publishable key readiness (do not skip):** call `queryAppAuth(action=\"getPublishableKey\")`. If it is empty, call `manageAppAuth(action=\"ensurePublishableKey\")` first — new environments may not have one provisioned, and skipping this step leaves the frontend without a data-plane credential, surfacing later as gateway auth failures instead of an obvious missing-key error.\n- **Persist the key, don't hoard it in conversation:** after retrieval, write the publishable key to `.env.local` as `VITE_PUBLISHABLE_KEY` (create the file if missing) and read it in client code via `import.meta.env.VITE_PUBLISHABLE_KEY`. Never hardcode the key into source files, and never ask the user to fetch it from the console — fall back to the console link below only if both MCP calls fail.\n- If `auth-tool-cloudbase` failed, let user go to `https:\u002F\u002Ftcb.cloud.tencent.com\u002Fdev?envId={env}#\u002Fenv\u002Fapikey` to get `publishable key` and `https:\u002F\u002Ftcb.cloud.tencent.com\u002Fdev?envId={env}#\u002Fidentity\u002Flogin-manage` to set up login methods\n\n### Parameter map\n\n- For username-style identifiers, the required precondition is `loginMethods.usernamePassword === true` from `queryAppAuth(action=\"getLoginConfig\")`. If it is false, enable it with `manageAppAuth(action=\"patchLoginStrategy\", patch={ usernamePassword: true })` before wiring frontend auth code.\n- If the conversation only provides an environment alias, nickname, or other shorthand, resolve it with `queryEnv(action=\"list\", alias=..., aliasExact=true)` first and use the returned canonical full `EnvId` for SDK init, console links, and generated config. Do not pass alias-like short forms directly into `cloudbase.init({ env })`.\n- Treat CloudBase Web Auth as **Supabase-like**, not “every `supabase-js` auth example is valid unchanged”\n- When `queryAppAuth` \u002F `manageAppAuth` returns `sdkStyle: \"supabase-like\"` and `sdkHints`, follow those method and parameter hints first\n- `auth.signInWithOtp({ phone })` and `auth.signUp({ phone })` use the phone number in a `phone` field, not `phone_number`\n- `auth.signInWithOtp({ email })` and `auth.signUp({ email })` use `email`\n- `auth.signInWithPassword({ username, password })` is the canonical Web login path for username\u002Fpassword accounts\n- Treat direct Web `auth.signUp({ username, password })` as conditional. Verify `sdkHints` and the installed SDK first; some versions only support `signUp` for OTP\u002Fprovider-token flows and will not create username\u002Fpassword users.\n- If the task gives accounts like `admin`, `editor`, or another plain string without `@`, treat it as a username-style identifier rather than an email address\n- `data.verifyOtp({ token })` — the `verifyOtp` callback on the `signInWithOtp` \u002F `signUp` result `data` — expects the SMS or email code in `token`; do not invent a standalone `auth.verifyOtp({ token })` call, which additionally requires `messageId`\n- `accessKey` is the publishable key from `queryAppAuth` \u002F `manageAppAuth` via `auth-tool-cloudbase`, not a secret key\n- **`accessKey` alone does not create a gateway-authenticated session.** Publishable `accessKey` initializes the SDK; it does **not** replace a login for NoSQL CRUD. Any `app.database()` `get` \u002F `add` \u002F `update` \u002F `watch` needs a session — prefer a real login (password \u002F OTP \u002F OAuth); `signInAnonymously()` only for explicitly-public demo data (disabled by default, denied AI model permissions). Otherwise the gateway returns **401**. Separately: the deprecated `auth.getLoginState()` may still return a misleading `uid` without login; use `auth.getSession()` for route guards (`data.session === undefined` when not logged in). `checkLogin()` \u002F `getSession()` alone do **not** create a usable write session.\n- Never set `accessKey` to `envId`, a username, or any placeholder string. If you do not have a real Publishable Key yet, do not fabricate one.\n- If the task mentions provider setup, stop and read `auth-tool-cloudbase` before writing frontend code\n\n## Quick Start\n\nSDK init reference: [docs.cloudbase.net\u002Fapi-reference\u002Fwebv3\u002Finitialization.md](https:\u002F\u002Fdocs.cloudbase.net\u002Fapi-reference\u002Fwebv3\u002Finitialization.md)（URL 加 `.md` 可取 raw markdown 原文）\n\n```js\n\u002F\u002F npm install @cloudbase\u002Fjs-sdk\nimport cloudbase from '@cloudbase\u002Fjs-sdk'\n\nconst app = cloudbase.init({\n  env: 'your-full-env-id', \u002F\u002F Canonical full CloudBase environment ID resolved from queryEnv or the console, not an alias or shorthand\n  region: 'ap-shanghai',  \u002F\u002F CloudBase environment Region, default 'ap-shanghai'\n  accessKey: 'publishable key', \u002F\u002F required, get from auth-tool-cloudbase\n  \u002F\u002F ⚠️ accessKey alone ≠ a login session. NoSQL CRUD needs a session —\n  \u002F\u002F real login preferred; signInAnonymously() only for public demo data.\n  \u002F\u002F Use auth.getSession() for route guards; deprecated getLoginState()\n  \u002F\u002F may return a misleading uid without a real session.\n  auth: { detectSessionInUrl: true }, \u002F\u002F required\n})\n\nconst auth = app.auth\n\n\u002F\u002F NoSQL app.database() CRUD requires a session (js-sdk 3.x + publishable key).\n\u002F\u002F Real login (see cookbook). Anonymous, only for public non-user demos:\n\u002F\u002F const { error } = await auth.signInAnonymously()\n\u002F\u002F if (error) throw error\n```\n\nIf the current task has not retrieved a real Publishable Key, omit `accessKey` instead of inventing one. A wrong `accessKey` can break auth-state checks and protected-route behavior.\n\n## Auth code cookbook (official v3 API — copy these, do not re-derive from .d.ts)\n\nEvery method returns the unified shape `{ data, error }` — branch on `error` first and surface `error.message`. The auth API is identical in traditional and PG environments. Source: [official auth docs](https:\u002F\u002Fdocs.cloudbase.net\u002Fapi-reference\u002Fwebv3\u002Fauthentication.md)（raw markdown, cross-check snippets there when in doubt）.\n\n**Default auth UI contract:** when the user asks for 登录\u002F注册\u002F账号体系\u002Fuser system without restricting the method, the login page must make ALL of these reachable (tabs or separate forms): password sign-in, OTP sign-in, verified sign-up (code + password), and forgot-password (whenever password sign-in exists). Never ship OTP-only or password-only UI unless explicitly asked. Never reveal whether an identifier is already registered in user-facing copy — route existing users to login with neutral wording.\n\n**Password sign-in** (username-style or email identifiers both go here):\n\n```js\nconst { data, error } = await auth.signInWithPassword({ username, password })\n\u002F\u002F email accounts: auth.signInWithPassword({ email, password })\nif (error) { \u002F* show error.message *\u002F } else { \u002F* data.user *\u002F }\n```\n\n**Anonymous sign-in — demo-only, not a default.** NoSQL `app.database()` CRUD needs some session (PG anon reads work with accessKey alone). Prefer a real login; reach for anonymous ONLY when the app explicitly serves public non-user data and the user accepts the trade-off — it is disabled by default, denied AI model permissions, and its `uid` must never own user-scoped rows:\n\n```js\nconst { error } = await auth.signInAnonymously()\n```\n\n**Registration — verification code is MANDATORY.** There is no password-only signup: `signUp` itself sends a code, and `data.verifyOtp` must complete it. Smart flow: existing identifier → plain login; new identifier → register + auto-login. Phone\u002FSMS is 上海地域 only — prefer email:\n\n```js\nconst { data, error } = await auth.signUp({ email, password }) \u002F\u002F or { phone, password }\nif (error) throw error\n\u002F\u002F user types the code from their inbox...\nconst { data: login, error: verifyErr } = await data.verifyOtp({ token: code })\n\u002F\u002F login.user \u002F login.session — signed in on both paths\n```\n\n**OTP sign-in (no password)** — same shape as `signUp`, auto-creates the user by default (`shouldCreateUser: false` to refuse unknown users). Requires 邮箱\u002F短信验证码登录 enabled in console → 身份认证\u002F登录方式:\n\n```js\nconst { data, error } = await auth.signInWithOtp({ email }) \u002F\u002F or { phone }\nconst { data: login, error: verifyErr } = await data.verifyOtp({ token: code })\n```\n\n**Forgot password** — email code → set new password → auto sign-in (emits `PASSWORD_RECOVERY`):\n\n```js\nconst { data, error } = await auth.resetPasswordForEmail(email)\nif (error) throw error\nconst { data: login, error: resetErr } = await data.updateUser({ nonce: code, password: newPassword })\n```\n\n**OTP closure vs standalone `verifyOtp` — do not mix.** The `data.verifyOtp` returned by `signUp` \u002F `signInWithOtp` \u002F `resetPasswordForEmail` has the message ID bound (pass only `{ token }`). The standalone `auth.verifyOtp(...)` requires `messageId` and **only logs in — it never registers**. Always use the returned closure.\n\n**Session check \u002F route guard** — always `getSession()`, never the deprecated `getLoginState()`:\n\n```js\nconst { data } = await auth.getSession()\nconst session = data?.session \u002F\u002F undefined === not logged in\n```\n\n**Auth state listener** (wire this once at app bootstrap):\n\n```js\nauth.onAuthStateChange((event, session) => {\n  \u002F\u002F event: INITIAL_SESSION | SIGNED_IN | SIGNED_OUT | PASSWORD_RECOVERY\n  \u002F\u002F        | TOKEN_REFRESHED | USER_UPDATED | BIND_IDENTITY\n})\n```\n\n**Sign out:**\n\n```js\nconst { error } = await auth.signOut()\n```\n\n**Mandatory auth gate before user-scoped data.** Before reading\u002Fwriting user-owned PG rows or Storage objects, check the session and show login when absent — never \"fix\" data errors by silently calling `signInAnonymously`:\n\n```js\nconst { data } = await auth.getSession()\nif (!data?.session) { navigate('\u002Flogin'); return }\n```\n\n**Completion Bar** — before calling the auth task done, the generated source must have ALL of:\n\n- [ ] `signInWithPassword` (when password login is part of the UI)\n- [ ] a verification-code path: `signUp` + `data.verifyOtp` and\u002For `signInWithOtp`\n- [ ] auth gate before user-scoped DB\u002FStorage calls (rule above)\n- [ ] `onAuthStateChange` wired at bootstrap (route guard reacts to `SIGNED_OUT`)\n- [ ] errors surfaced from `error.message`, no invented error text\n- [ ] NO `signInAnonymously` as a fallback for permission errors, no mock\u002FlocalStorage sessions\n\n---\n\n## Extended guide\n\nFor detailed scenarios, examples, and patterns, read [extended-guide.md](references\u002Fextended-guide.md).\n\n## Reference index\n\nAll packaged reference files (required for skill lint reachability):\n\n- [extended-guide.md](references\u002Fextended-guide.md)\n",{"name":5,"license":14,"version":23,"alwaysApply":19,"description":7},"2.36.2","main","33b6151ccee9aa0816c6f32d021be77d82772755","connectors\u002Fcloudbase\u002Fskills\u002Freferences\u002Fauth-web-cloudbase",138,"https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills","https:\u002F\u002Fgithub.com\u002Finfometa","2026-11-11 03:15:35",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add infometa\u002Fworkbuddyskills --skill auth-web-cloudbase",{"tool":37,"command":38},"bunx","bunx skills add infometa\u002Fworkbuddyskills --skill auth-web-cloudbase",{"tool":40,"command":41},"pnpm","pnpm dlx skills add infometa\u002Fworkbuddyskills --skill auth-web-cloudbase","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fconnectors\u002Fcloudbase\u002Fskills\u002Freferences\u002Fauth-web-cloudbase\u002FSKILL.md",true,[45],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":50},"references\u002Fextended-guide.md","REFERENCE","参考文档",14005,"https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fconnectors\u002Fcloudbase\u002Fskills\u002Freferences\u002Fauth-web-cloudbase\u002Freferences\u002Fextended-guide.md",[52,59,66,73,80,89],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":18},"01M7A1EC013S1PBBTSH2PA2S7D","yingmi-skill","当用户需要查询基金、策略、公告、财经资讯，做资产配置、组合诊断、风险回测、现金流分析，或生成图表、PDF 时，优先使用本 Skill 获取真实数据与可执行能力。","https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fskills\u002Fyingmi-skill\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":18},"01M7A194T67P6NRVYK8KCTH3CH","web-access","所有联网操作必须通过此 skill 处理，包括：搜索、网页抓取、登录后操作、网络交互等。","https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fskills\u002Fweb-access\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":18},"01M7A14FATMDD6FK8QAGXY5GVR","tencentmap-map-assistant","腾讯位置服务·地图助手 Skill，一句自然语言调用腾讯地图全套能力，无需开发者账号、开箱即用。提供 AI 旅游攻略、地点搜索（含评分\u002F人均\u002F营业时间）、关键词提示、路线规划（驾车\u002F步行\u002F公交\u002F骑行）、地址解析与逆解析、行政区划、IP 定位、距离计算、天气查询，并可将行程或多 POI 渲染成网页地图。涉及找地点、规划路线、旅游行程、查天气、坐标转换等出行场景时使用。","https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fskills\u002Ftencentmap-map-assistant\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M7A0SX4XW5053MZ2S921EDH2","skill-scanner","Scan any agent skill for security risks before you install or use it. Powered by Tencent Zhuque Lab A.I.G (AI-Infra-Guard). 100% local static analysis — no file contents or credentials leave your device. Compatible with CodeBuddy, Cursor, Windsurf, Claude Code, OpenClaw and more. Triggers on: 这个 skill 安全吗, skill 安全扫描, 检查 skill 安全, audit skill, scan skill, check skill safety, analyze skill, inspect skill, verify skill, skill security, skill supply chain. Do NOT trigger for general agent usage, full system health checks, project debugging, or normal development.","https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fskills\u002Fskill-scanner\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":84,"licenseFileUrl":85,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":18},"01M7A0SQC2CZB3450G8471673M","skill-creator","Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends agent capabilities with specialized knowledge, workflows, or tool integrations.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fskills\u002Fskill-creator\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fskills\u002Fskill-creator\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":18},"01M7A0RHV7BKS7DFQF9X9QCCNN","shader-dev","Comprehensive GLSL shader techniques for creating stunning visual effects — ray marching, SDF modeling, fluid simulation, particle systems, procedural generation, lighting, post-processing, and more.","https:\u002F\u002Fgithub.com\u002Finfometa\u002Fworkbuddyskills\u002Fblob\u002Fmain\u002Fskills\u002Fshader-dev\u002FSKILL.md",[],[]]