[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BWV3KX5NB0AE02CMNNWT40":3,"skill-same:01M7BWV3KX5NB0AE02CMNNWT40":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":6,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M7BWV3KX5NB0AE02CMNNWT40","auth-nodejs-cloudbase",null,"Complete guide for CloudBase Auth using the CloudBase Node SDK – caller identity, user lookup, custom login tickets, and server-side best practices.","YYC-Cube\u002FYYC3-Knowledge-Base","YYC-Cube","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235006543?v=4","01M79J2PH4SWD2X0825X6PN748","yyc3","01M79J2PHVK3F6ZBYT8K2SCZCW",1,"MIT","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Plugin-插件协议\u002FYYC3-Plugin-插件协议-plugins\u002Fcloudbase\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-nodejs\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: auth-nodejs-cloudbase\ndescription: Complete guide for CloudBase Auth using the CloudBase Node SDK – caller identity, user lookup, custom login tickets, and server-side best practices.\nalwaysApply: false\n---\n\n## When to use this skill\n\nUse this skill whenever the task involves **server-side authentication or identity** in a CloudBase project, and the code is running in **Node.js**, for example:\n\n- CloudBase 云函数 (Node runtime) that needs to know **who is calling**\n- Node services that use **CloudBase Node SDK** to look up user information\n- Backends that issue **custom login tickets** for Web \u002F mobile clients\n- Admin or ops tools that need to inspect CloudBase end-user profiles\n\n**Do NOT use this skill for:**\n\n- Frontend Web login \u002F sign-up flows using `@cloudbase\u002Fjs-sdk` (handle those with the **auth-web** skill, not this Node skill).\n- Direct HTTP auth API integrations (this skill does not describe raw HTTP endpoints; use the **http-api** skill instead).\n- Database or storage operations that do not involve identity (use database\u002Fstorage docs or skills).\n\nWhen the user request mixes frontend and backend concerns (e.g. \"build a web login page and a Node API that knows the user\"), treat them separately:\n\n- Use Web-side auth docs\u002Fskills for client login and UX.\n- Use this Node Auth skill for how the backend sees and uses the authenticated user.\n\n---\n\n## How to use this skill (for a coding agent)\n\nWhen you load this skill to work on a task:\n\n1. **Clarify the runtime and responsibility**\n\n   Ask the user:\n\n   - Where does this Node code run?\n     - CloudBase 云函数\n     - Long‑running Node service using CloudBase\n   - What do they need from auth?\n     - Just the **caller identity** for authorization?\n     - **Look up arbitrary users** by UID \u002F login identifier?\n     - **Bridge their own user system** into CloudBase via custom login?\n\n2. **Confirm CloudBase environment and SDK**\n\n   - Ask for:\n     - `env` – CloudBase environment ID\n   - Install the latest `@cloudbase\u002Fnode-sdk` from npm if it is not already available.\n   - Always initialize the SDK using this pattern (values can change, shape must not):\n\n   ```ts\n   import tcb from \"@cloudbase\u002Fnode-sdk\";\n\n   const app = tcb.init({ env: \"your-env-id\" });\n   const auth = app.auth();\n   ```\n\n3. **Pick the relevant scenario from this file**\n\n   - For **caller identity inside a function**, use the `getUserInfo` scenarios.\n   - For **full user profile or admin lookup**, use the `getEndUserInfo` and `queryUserInfo` scenarios.\n   - For **client systems that already have their own users**, use the **custom login ticket** scenarios built on `createTicket`.\n   - For **logging \u002F security**, use the `getClientIP` scenario.\n\n4. **Follow Node SDK API shapes exactly**\n\n   - Treat all `auth.*` methods and parameter shapes in this file as canonical.\n   - You may change variable names and framework (e.g. Express vs 云函数 handler), but **do not change SDK method names or parameter fields**.\n   - If you see a method in older code that is not listed here or in the Node SDK docs mirror, treat it as suspect and avoid using it.\n\n5. **If you are unsure about an API**\n\n   - Consult the official CloudBase Auth Node SDK documentation.\n   - Only use methods and shapes that appear in the official documentation.\n   - If you cannot find an API you want:\n     - Prefer composing flows from the documented methods, or\n     - Explain that this skill only covers Node SDK auth, and suggest using the relevant CloudBase Web or HTTP auth documentation for client-side or raw-HTTP flows.\n\n---\n\n## Node auth architecture – how Node fits into CloudBase Auth\n\nCloudBase Auth v2 separates **where users log in** from **where backend code runs**:\n\n- Users log in through the supported auth methods (anonymous, username\u002Fpassword, SMS, email, WeChat, custom login, etc.) using client SDKs or HTTP interfaces, as described in the official CloudBase Auth overview documentation.\n- Once logged in, CloudBase attaches the user identity and tokens to the environment.\n- Node code then **reads** that identity using the Node SDK, or **bridges** external identities into CloudBase using custom login.\n\nIn practice, Node code usually does one or more of:\n\n1. **Identify the current caller**\n\n   - In 云函数, use `auth.getUserInfo()` to read `uid`, `openId`, and `customUserId`.\n   - Use this identity for **authorization decisions**, logging, and personalisation.\n\n2. **Look up other users**\n\n   - Use `auth.getEndUserInfo(uid)` when you know the CloudBase `uid`.\n   - Use `auth.queryUserInfo({ platform, platformId, uid? })` when you only have login identifiers such as phone, email, username, or a custom ID.\n\n3. **Issue custom login tickets**\n\n   - When you already have your own user system, your Node backend can call `auth.createTicket(customUserId, options)` and return the ticket to a trusted client.\n   - The client (typically Web) then uses this ticket with the Web SDK to log the user into CloudBase without forcing them to sign up again.\n\n4. **Log client IP for security**\n\n   - In 云函数, `auth.getClientIP()` returns the caller IP, which you can use for audit logs, anomaly detection, or access control.\n\nThe scenarios later in this file turn these responsibilities into explicit, copy‑pasteable patterns.\n\n---\n\n## Node Auth APIs covered by this skill\n\nThis skill covers the following `auth` methods on the CloudBase Node SDK. Treat these method signatures as the only supported entry points for Node auth flows when using this skill:\n\n- `getUserInfo(): IGetUserInfoResult`\n  Returns `{ openId, appId, uid, customUserId }` for the **current caller**.\n\n- `getEndUserInfo(uid?: string, opts?: ICustomReqOpts): Promise\u003C{ userInfo: EndUserInfo; requestId?: string }>`\n  Returns detailed CloudBase end‑user profile for a given `uid` or for the current caller (when `uid` is omitted).\n\n- `queryUserInfo(query: IUserInfoQuery, opts?: ICustomReqOpts): Promise\u003C{ userInfo: EndUserInfo; requestId?: string }>`\n  Finds a user by login identifier (`platform` + `platformId`) or `uid`.\n\n- `getClientIP(): string`\n  Returns the caller’s IP address when running in a supported environment (e.g. 云函数).\n\n- `createTicket(customUserId: string, options?: ICreateTicketOpts): string`\n  Creates a **custom login ticket** for the given `customUserId` that clients can exchange for a CloudBase login.\n\nThe exact field names and allowed values for `EndUserInfo`, `IUserInfoQuery`, and `ICreateTicketOpts` are defined by the official CloudBase Node SDK typings and documentation. When writing Node code, do not guess shapes; follow the SDK types and the examples in this file.\n\n---\n\n## Scenarios – Node auth patterns\n\n### Scenario 1: Initialize Node SDK and auth in a CloudBase function\n\nUse this when writing a CloudBase 云函数 that needs to interact with Auth:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  \u002F\u002F Your logic here\n};\n```\n\nKey points:\n\n- Use the same `env` as configured for the function’s CloudBase 环境.\n- Avoid hardcoding sensitive values; prefer environment variables or function configuration.\n\n### Scenario 2: Get caller identity in a CloudBase function\n\nUse this when you need to know **who is calling** your cloud function:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  const { openId, appId, uid, customUserId } = auth.getUserInfo();\n\n  console.log(\"Caller identity\", { openId, appId, uid, customUserId });\n\n  \u002F\u002F Use uid \u002F customUserId for authorization decisions\n  \u002F\u002F e.g. check roles, permissions, or data ownership\n};\n```\n\nBest practices:\n\n- Treat `uid` as the canonical CloudBase user identifier.\n- Use `customUserId` only when you have enabled **自定义登录** and mapped your own users.\n- Never trust `openId`\u002F`appId` alone for authorization; they are WeChat‑specific identifiers.\n\n### Scenario 3: Get full end‑user profile by UID\n\nUse this when you know a user’s CloudBase `uid` (for example, from a database record) and you need detailed profile information:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  const uid = \"user-uid\";\n\n  try {\n    const { userInfo } = await auth.getEndUserInfo(uid);\n    console.log(\"User profile\", userInfo);\n  } catch (error) {\n    console.error(\"Failed to get end user info\", error.message);\n  }\n};\n```\n\nBest practices:\n\n- Call `getEndUserInfo` from trusted backend code only; do not expose it directly to untrusted clients.\n- Log minimal necessary data for debugging; avoid logging full profiles in production.\n\n### Scenario 4: Get full profile for the current caller\n\nUse this when you want the **current caller’s** full profile without manually passing `uid`:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  try {\n    const { userInfo } = await auth.getEndUserInfo();\n    console.log(\"Current caller profile\", userInfo);\n  } catch (error) {\n    console.error(\"Failed to get current caller profile\", error.message);\n  }\n};\n```\n\nThis relies on the environment providing the caller’s identity (e.g. within a CloudBase 云函数). If called where no caller context exists, refer to the official docs and handle errors gracefully.\n\n### Scenario 5: Query user by login identifier\n\nUse this when you only know a user’s login identifier (phone, email, username, or custom ID) and need their CloudBase profile:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  try {\n    \u002F\u002F Find by phone number\n    const { userInfo: byPhone } = await auth.queryUserInfo({\n      platform: \"PHONE\",\n      platformId: \"+86 13800000000\",\n    });\n\n    \u002F\u002F Find by email\n    const { userInfo: byEmail } = await auth.queryUserInfo({\n      platform: \"EMAIL\",\n      platformId: \"test@example.com\",\n    });\n\n    \u002F\u002F Find by customUserId\n    const { userInfo: byCustomId } = await auth.queryUserInfo({\n      platform: \"CUSTOM\",\n      platformId: \"your-customUserId\",\n    });\n\n    console.log({ byPhone, byEmail, byCustomId });\n  } catch (error) {\n    console.error(\"Failed to query user info\", error.message);\n  }\n};\n```\n\nBest practices:\n\n- Prefer `uid` when you already have it; use `queryUserInfo` only when needed.\n- Make sure `platformId` uses the exact format you used at sign‑up (e.g. `+86` + phone number).\n\n### Scenario 6: Get client IP in a function\n\nUse this for logging or basic IP‑based checks:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  const ip = auth.getClientIP();\n  console.log(\"Caller IP\", ip);\n\n  \u002F\u002F e.g. block or flag suspicious IPs\n};\n```\n\n---\n\n## Custom login tickets (Node side only)\n\nCustom login lets you keep your existing user system while still mapping each user to a CloudBase account.\n\n### Scenario 7: Initialize Node SDK with custom login credentials\n\nBefore issuing tickets, install the custom login private key file from the CloudBase console and load it in Node:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\nimport path from \"node:path\";\n\nconst app = tcb.init({\n  env: \"your-env-id\",\n  credentials: require(path.join(__dirname, \"tcb_custom_login.json\")),\n});\n\nconst auth = app.auth();\n```\n\nKeep `tcb_custom_login.json` secret and **never** bundle it into frontend code.\n\n### Scenario 8: Issue a custom login ticket for a given customUserId\n\nUse this in backend code that has already authenticated your own user and wants to let them log into CloudBase:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({\n  env: \"your-env-id\",\n  credentials: require(\"\u002Fsecure\u002Fpath\u002Fto\u002Ftcb_custom_login.json\"),\n});\n\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  const customUserId = \"your-customUserId\";\n\n  const ticket = auth.createTicket(customUserId, {\n    refresh: 3600 * 1000,       \u002F\u002F access_token refresh interval (ms)\n    expire: 24 * 3600 * 1000,   \u002F\u002F ticket expiration time (ms)\n  });\n\n  \u002F\u002F Return the ticket to the trusted client (e.g. via HTTP response)\n  return { ticket };\n};\n```\n\nConstraints for `customUserId` (from official docs):\n\n- Length 4–32 characters.\n- Allowed characters: letters, digits, and `_-#@(){}[]:.,\u003C>+#~`.\n\nBest practices:\n\n- Only issue tickets after your own user authentication succeeds.\n- Store `customUserId` in your own user database and keep it stable over time.\n- Do not reuse `customUserId` for multiple distinct people.\n\n### Scenario 9: How this pairs with Web custom login\n\nThis skill only covers **Node-side** ticket issuance. For the **client-side** flow:\n\n- On the client (Web), use `@cloudbase\u002Fjs-sdk`'s custom login support:\n  - Call your backend endpoint that returns `ticket`.\n  - Configure `auth.setCustomSignFunc(async () => ticketFromBackend)`.\n  - Call `auth.signInWithCustomTicket()` to finish login.\n\nKeep the responsibility clear:\n\n- Node: authenticate your own user → create ticket → return ticket securely.\n- Web: receive ticket → sign into CloudBase using documented Web SDK APIs.\n\n---\n\n## Node auth best practices\n\n- **Single source of truth for identity**\n  - Treat CloudBase `uid` as the primary key when relating end‑user records.\n  - Use `customUserId` only as a bridge to your own user system.\n\n- **Least privilege**\n  - Perform authorization checks in Node using `uid`, roles, and ownership, not just login success.\n  - Avoid exposing raw `getEndUserInfo` \u002F `queryUserInfo` results directly to clients.\n\n- **Error handling**\n  - Wrap all `auth.*` calls in `try\u002Fcatch` when they return promises.\n  - Log `error.message` (and `error.code` if present), but avoid logging sensitive data.\n\n- **Security**\n  - Protect `tcb_custom_login.json` as you would any private key.\n  - Rotate custom login keys according to CloudBase guidance when necessary.\n  - Use HTTPS and proper authentication between your clients and Node backend when exchanging tickets.\n\n---\n\n## Summary\n\nUse this Node Auth skill whenever you need to:\n\n- Know **who** is calling your Node code in CloudBase.\n- Look up CloudBase users by `uid` or login identifier.\n- Bridge an existing user system into CloudBase with **custom login tickets**.\n- Apply consistent, secure, server‑side auth best practices.\n\nFor end‑to‑end experiences, pair this skill with:\n\n- Web‑side auth documentation (for all browser‑side login and UX using `@cloudbase\u002Fjs-sdk`).\n- CloudBase HTTP auth documentation (for language‑agnostic HTTP integrations, if you are using those).\n\nTreat the official CloudBase Auth Node SDK documentation as the canonical reference for Node auth APIs, and treat the scenarios in this file as vetted best‑practice building blocks.\n","## When to use this skill\n\nUse this skill whenever the task involves **server-side authentication or identity** in a CloudBase project, and the code is running in **Node.js**, for example:\n\n- CloudBase 云函数 (Node runtime) that needs to know **who is calling**\n- Node services that use **CloudBase Node SDK** to look up user information\n- Backends that issue **custom login tickets** for Web \u002F mobile clients\n- Admin or ops tools that need to inspect CloudBase end-user profiles\n\n**Do NOT use this skill for:**\n\n- Frontend Web login \u002F sign-up flows using `@cloudbase\u002Fjs-sdk` (handle those with the **auth-web** skill, not this Node skill).\n- Direct HTTP auth API integrations (this skill does not describe raw HTTP endpoints; use the **http-api** skill instead).\n- Database or storage operations that do not involve identity (use database\u002Fstorage docs or skills).\n\nWhen the user request mixes frontend and backend concerns (e.g. \"build a web login page and a Node API that knows the user\"), treat them separately:\n\n- Use Web-side auth docs\u002Fskills for client login and UX.\n- Use this Node Auth skill for how the backend sees and uses the authenticated user.\n\n---\n\n## How to use this skill (for a coding agent)\n\nWhen you load this skill to work on a task:\n\n1. **Clarify the runtime and responsibility**\n\n   Ask the user:\n\n   - Where does this Node code run?\n     - CloudBase 云函数\n     - Long‑running Node service using CloudBase\n   - What do they need from auth?\n     - Just the **caller identity** for authorization?\n     - **Look up arbitrary users** by UID \u002F login identifier?\n     - **Bridge their own user system** into CloudBase via custom login?\n\n2. **Confirm CloudBase environment and SDK**\n\n   - Ask for:\n     - `env` – CloudBase environment ID\n   - Install the latest `@cloudbase\u002Fnode-sdk` from npm if it is not already available.\n   - Always initialize the SDK using this pattern (values can change, shape must not):\n\n   ```ts\n   import tcb from \"@cloudbase\u002Fnode-sdk\";\n\n   const app = tcb.init({ env: \"your-env-id\" });\n   const auth = app.auth();\n   ```\n\n3. **Pick the relevant scenario from this file**\n\n   - For **caller identity inside a function**, use the `getUserInfo` scenarios.\n   - For **full user profile or admin lookup**, use the `getEndUserInfo` and `queryUserInfo` scenarios.\n   - For **client systems that already have their own users**, use the **custom login ticket** scenarios built on `createTicket`.\n   - For **logging \u002F security**, use the `getClientIP` scenario.\n\n4. **Follow Node SDK API shapes exactly**\n\n   - Treat all `auth.*` methods and parameter shapes in this file as canonical.\n   - You may change variable names and framework (e.g. Express vs 云函数 handler), but **do not change SDK method names or parameter fields**.\n   - If you see a method in older code that is not listed here or in the Node SDK docs mirror, treat it as suspect and avoid using it.\n\n5. **If you are unsure about an API**\n\n   - Consult the official CloudBase Auth Node SDK documentation.\n   - Only use methods and shapes that appear in the official documentation.\n   - If you cannot find an API you want:\n     - Prefer composing flows from the documented methods, or\n     - Explain that this skill only covers Node SDK auth, and suggest using the relevant CloudBase Web or HTTP auth documentation for client-side or raw-HTTP flows.\n\n---\n\n## Node auth architecture – how Node fits into CloudBase Auth\n\nCloudBase Auth v2 separates **where users log in** from **where backend code runs**:\n\n- Users log in through the supported auth methods (anonymous, username\u002Fpassword, SMS, email, WeChat, custom login, etc.) using client SDKs or HTTP interfaces, as described in the official CloudBase Auth overview documentation.\n- Once logged in, CloudBase attaches the user identity and tokens to the environment.\n- Node code then **reads** that identity using the Node SDK, or **bridges** external identities into CloudBase using custom login.\n\nIn practice, Node code usually does one or more of:\n\n1. **Identify the current caller**\n\n   - In 云函数, use `auth.getUserInfo()` to read `uid`, `openId`, and `customUserId`.\n   - Use this identity for **authorization decisions**, logging, and personalisation.\n\n2. **Look up other users**\n\n   - Use `auth.getEndUserInfo(uid)` when you know the CloudBase `uid`.\n   - Use `auth.queryUserInfo({ platform, platformId, uid? })` when you only have login identifiers such as phone, email, username, or a custom ID.\n\n3. **Issue custom login tickets**\n\n   - When you already have your own user system, your Node backend can call `auth.createTicket(customUserId, options)` and return the ticket to a trusted client.\n   - The client (typically Web) then uses this ticket with the Web SDK to log the user into CloudBase without forcing them to sign up again.\n\n4. **Log client IP for security**\n\n   - In 云函数, `auth.getClientIP()` returns the caller IP, which you can use for audit logs, anomaly detection, or access control.\n\nThe scenarios later in this file turn these responsibilities into explicit, copy‑pasteable patterns.\n\n---\n\n## Node Auth APIs covered by this skill\n\nThis skill covers the following `auth` methods on the CloudBase Node SDK. Treat these method signatures as the only supported entry points for Node auth flows when using this skill:\n\n- `getUserInfo(): IGetUserInfoResult`\n  Returns `{ openId, appId, uid, customUserId }` for the **current caller**.\n\n- `getEndUserInfo(uid?: string, opts?: ICustomReqOpts): Promise\u003C{ userInfo: EndUserInfo; requestId?: string }>`\n  Returns detailed CloudBase end‑user profile for a given `uid` or for the current caller (when `uid` is omitted).\n\n- `queryUserInfo(query: IUserInfoQuery, opts?: ICustomReqOpts): Promise\u003C{ userInfo: EndUserInfo; requestId?: string }>`\n  Finds a user by login identifier (`platform` + `platformId`) or `uid`.\n\n- `getClientIP(): string`\n  Returns the caller’s IP address when running in a supported environment (e.g. 云函数).\n\n- `createTicket(customUserId: string, options?: ICreateTicketOpts): string`\n  Creates a **custom login ticket** for the given `customUserId` that clients can exchange for a CloudBase login.\n\nThe exact field names and allowed values for `EndUserInfo`, `IUserInfoQuery`, and `ICreateTicketOpts` are defined by the official CloudBase Node SDK typings and documentation. When writing Node code, do not guess shapes; follow the SDK types and the examples in this file.\n\n---\n\n## Scenarios – Node auth patterns\n\n### Scenario 1: Initialize Node SDK and auth in a CloudBase function\n\nUse this when writing a CloudBase 云函数 that needs to interact with Auth:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  \u002F\u002F Your logic here\n};\n```\n\nKey points:\n\n- Use the same `env` as configured for the function’s CloudBase 环境.\n- Avoid hardcoding sensitive values; prefer environment variables or function configuration.\n\n### Scenario 2: Get caller identity in a CloudBase function\n\nUse this when you need to know **who is calling** your cloud function:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  const { openId, appId, uid, customUserId } = auth.getUserInfo();\n\n  console.log(\"Caller identity\", { openId, appId, uid, customUserId });\n\n  \u002F\u002F Use uid \u002F customUserId for authorization decisions\n  \u002F\u002F e.g. check roles, permissions, or data ownership\n};\n```\n\nBest practices:\n\n- Treat `uid` as the canonical CloudBase user identifier.\n- Use `customUserId` only when you have enabled **自定义登录** and mapped your own users.\n- Never trust `openId`\u002F`appId` alone for authorization; they are WeChat‑specific identifiers.\n\n### Scenario 3: Get full end‑user profile by UID\n\nUse this when you know a user’s CloudBase `uid` (for example, from a database record) and you need detailed profile information:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  const uid = \"user-uid\";\n\n  try {\n    const { userInfo } = await auth.getEndUserInfo(uid);\n    console.log(\"User profile\", userInfo);\n  } catch (error) {\n    console.error(\"Failed to get end user info\", error.message);\n  }\n};\n```\n\nBest practices:\n\n- Call `getEndUserInfo` from trusted backend code only; do not expose it directly to untrusted clients.\n- Log minimal necessary data for debugging; avoid logging full profiles in production.\n\n### Scenario 4: Get full profile for the current caller\n\nUse this when you want the **current caller’s** full profile without manually passing `uid`:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  try {\n    const { userInfo } = await auth.getEndUserInfo();\n    console.log(\"Current caller profile\", userInfo);\n  } catch (error) {\n    console.error(\"Failed to get current caller profile\", error.message);\n  }\n};\n```\n\nThis relies on the environment providing the caller’s identity (e.g. within a CloudBase 云函数). If called where no caller context exists, refer to the official docs and handle errors gracefully.\n\n### Scenario 5: Query user by login identifier\n\nUse this when you only know a user’s login identifier (phone, email, username, or custom ID) and need their CloudBase profile:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  try {\n    \u002F\u002F Find by phone number\n    const { userInfo: byPhone } = await auth.queryUserInfo({\n      platform: \"PHONE\",\n      platformId: \"+86 13800000000\",\n    });\n\n    \u002F\u002F Find by email\n    const { userInfo: byEmail } = await auth.queryUserInfo({\n      platform: \"EMAIL\",\n      platformId: \"test@example.com\",\n    });\n\n    \u002F\u002F Find by customUserId\n    const { userInfo: byCustomId } = await auth.queryUserInfo({\n      platform: \"CUSTOM\",\n      platformId: \"your-customUserId\",\n    });\n\n    console.log({ byPhone, byEmail, byCustomId });\n  } catch (error) {\n    console.error(\"Failed to query user info\", error.message);\n  }\n};\n```\n\nBest practices:\n\n- Prefer `uid` when you already have it; use `queryUserInfo` only when needed.\n- Make sure `platformId` uses the exact format you used at sign‑up (e.g. `+86` + phone number).\n\n### Scenario 6: Get client IP in a function\n\nUse this for logging or basic IP‑based checks:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({ env: \"your-env-id\" });\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  const ip = auth.getClientIP();\n  console.log(\"Caller IP\", ip);\n\n  \u002F\u002F e.g. block or flag suspicious IPs\n};\n```\n\n---\n\n## Custom login tickets (Node side only)\n\nCustom login lets you keep your existing user system while still mapping each user to a CloudBase account.\n\n### Scenario 7: Initialize Node SDK with custom login credentials\n\nBefore issuing tickets, install the custom login private key file from the CloudBase console and load it in Node:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\nimport path from \"node:path\";\n\nconst app = tcb.init({\n  env: \"your-env-id\",\n  credentials: require(path.join(__dirname, \"tcb_custom_login.json\")),\n});\n\nconst auth = app.auth();\n```\n\nKeep `tcb_custom_login.json` secret and **never** bundle it into frontend code.\n\n### Scenario 8: Issue a custom login ticket for a given customUserId\n\nUse this in backend code that has already authenticated your own user and wants to let them log into CloudBase:\n\n```ts\nimport tcb from \"@cloudbase\u002Fnode-sdk\";\n\nconst app = tcb.init({\n  env: \"your-env-id\",\n  credentials: require(\"\u002Fsecure\u002Fpath\u002Fto\u002Ftcb_custom_login.json\"),\n});\n\nconst auth = app.auth();\n\nexports.main = async (event, context) => {\n  const customUserId = \"your-customUserId\";\n\n  const ticket = auth.createTicket(customUserId, {\n    refresh: 3600 * 1000,       \u002F\u002F access_token refresh interval (ms)\n    expire: 24 * 3600 * 1000,   \u002F\u002F ticket expiration time (ms)\n  });\n\n  \u002F\u002F Return the ticket to the trusted client (e.g. via HTTP response)\n  return { ticket };\n};\n```\n\nConstraints for `customUserId` (from official docs):\n\n- Length 4–32 characters.\n- Allowed characters: letters, digits, and `_-#@(){}[]:.,\u003C>+#~`.\n\nBest practices:\n\n- Only issue tickets after your own user authentication succeeds.\n- Store `customUserId` in your own user database and keep it stable over time.\n- Do not reuse `customUserId` for multiple distinct people.\n\n### Scenario 9: How this pairs with Web custom login\n\nThis skill only covers **Node-side** ticket issuance. For the **client-side** flow:\n\n- On the client (Web), use `@cloudbase\u002Fjs-sdk`'s custom login support:\n  - Call your backend endpoint that returns `ticket`.\n  - Configure `auth.setCustomSignFunc(async () => ticketFromBackend)`.\n  - Call `auth.signInWithCustomTicket()` to finish login.\n\nKeep the responsibility clear:\n\n- Node: authenticate your own user → create ticket → return ticket securely.\n- Web: receive ticket → sign into CloudBase using documented Web SDK APIs.\n\n---\n\n## Node auth best practices\n\n- **Single source of truth for identity**\n  - Treat CloudBase `uid` as the primary key when relating end‑user records.\n  - Use `customUserId` only as a bridge to your own user system.\n\n- **Least privilege**\n  - Perform authorization checks in Node using `uid`, roles, and ownership, not just login success.\n  - Avoid exposing raw `getEndUserInfo` \u002F `queryUserInfo` results directly to clients.\n\n- **Error handling**\n  - Wrap all `auth.*` calls in `try\u002Fcatch` when they return promises.\n  - Log `error.message` (and `error.code` if present), but avoid logging sensitive data.\n\n- **Security**\n  - Protect `tcb_custom_login.json` as you would any private key.\n  - Rotate custom login keys according to CloudBase guidance when necessary.\n  - Use HTTPS and proper authentication between your clients and Node backend when exchanging tickets.\n\n---\n\n## Summary\n\nUse this Node Auth skill whenever you need to:\n\n- Know **who** is calling your Node code in CloudBase.\n- Look up CloudBase users by `uid` or login identifier.\n- Bridge an existing user system into CloudBase with **custom login tickets**.\n- Apply consistent, secure, server‑side auth best practices.\n\nFor end‑to‑end experiences, pair this skill with:\n\n- Web‑side auth documentation (for all browser‑side login and UX using `@cloudbase\u002Fjs-sdk`).\n- CloudBase HTTP auth documentation (for language‑agnostic HTTP integrations, if you are using those).\n\nTreat the official CloudBase Auth Node SDK documentation as the canonical reference for Node auth APIs, and treat the scenarios in this file as vetted best‑practice building blocks.\n",{"name":5,"alwaysApply":20,"description":7},"main","87afe6ce96220accf50a345dea46784c8c9f210e","YYC3-Plugin-插件协议\u002FYYC3-Plugin-插件协议-plugins\u002Fcloudbase\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-nodejs",0,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base","https:\u002F\u002Fkb.yyc3.top\u002F","https:\u002F\u002Fgithub.com\u002FYYC-Cube","万象归元于云枢 | 深栈智启新纪元","2026-11-10 10:37:32",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill auth-nodejs-cloudbase",{"tool":39,"command":40},"bunx","bunx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill auth-nodejs-cloudbase",{"tool":42,"command":43},"pnpm","pnpm dlx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill auth-nodejs-cloudbase","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Plugin-插件协议\u002FYYC3-Plugin-插件协议-plugins\u002Fcloudbase\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-nodejs\u002FSKILL.md",true,[],[48,55,62,69,76,83],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M7CTDWHERCXPQCP0K03A86AS","vercel-sandbox","Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include \"Vercel Sandbox browser\", \"microVM Chrome\", \"agent-browser in sandbox\", \"browser automation on Vercel\", or any task requiring Chrome in a Vercel Sandbox.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fvercel-sandbox\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M7CTD8D2BNJY54S65M47HEJA","slack","Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include \"check my Slack\", \"what channels have unreads\", \"send a message to\", \"search Slack for\", \"extract from Slack\", \"find who said\", or any task requiring programmatic Slack interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fslack\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M7CTCSSB8ZP3Q58C3YZDZK1W","electron","Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include \"automate Slack app\", \"control VS Code\", \"interact with Discord app\", \"test this Electron app\", \"connect to desktop app\", or any task requiring automation of a native Electron application.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Felectron\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7CTCBJY76688V4DCZGWFHGQ","dogfood","Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to \"dogfood\", \"QA\", \"exploratory test\", \"find issues\", \"bug hunt\", \"test this app\u002Fsite\u002Fplatform\", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fdogfood\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7CTC4H0FFGVEAQR9PA4GA1A","agent-browser","Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to \"open a website\", \"fill out a form\", \"click a button\", \"take a screenshot\", \"scrape data from a page\", \"test this web app\", \"login to a site\", \"automate browser actions\", or any task requiring programmatic web interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fagent-browser\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M7CTBKVFYBG78FDSABSDJTTQ","shadcn","Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn\u002Fui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for \"shadcn init\", \"create an app with --preset\", \"switch to --preset\", and for building a design system or applying a DESIGN.md or brand spec to shadcn\u002Fui.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-UI-界面组件\u002FYYC3-UI-界面组件-ui\u002Fskills\u002Fshadcn\u002FSKILL.md",[],[]]