[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6HSAYM87JSYNYK4Z1SFGA9S":3,"skill-same:01M6HSAYM87JSYNYK4Z1SFGA9S":63},{"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":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":45,"repositoryHtmlUrl":46,"repositoryHomepageUrl":6,"ownerHtmlUrl":47,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":48,"install":49,"resources":62},"01M6HSAYM87JSYNYK4Z1SFGA9S","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.","welflau\u002Fai-dev-system","welflau","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F7010385?v=4","01M6HPTDGF18RFY07M229P8CTM","01M6HPTDMRMZCJPYBFEA9XVVYT",3,"MIT","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Fcloudbase\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-nodejs\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],"auth","auth nodejs cloudbase","nodejs","cloudbase","custom","sdk","for","login","tickets","complete","false","server-side","guide","user","node","lookup","server","best practices","identity","2026-11-10 10:12:30",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":38,"description":7},"main","18d0e63d1313ca87098f614aa7c1e2dcf6de79c7","backend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Fcloudbase\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-nodejs",1,"https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system","https:\u002F\u002Fgithub.com\u002Fwelflau","2026-11-10 11:14:25",{"source":8,"skillName":5,"commands":50,"prompt":60,"zipAvailable":61},[51,54,57],{"tool":52,"command":53},"npx","npx skills add welflau\u002Fai-dev-system --skill auth-nodejs-cloudbase",{"tool":55,"command":56},"bunx","bunx skills add welflau\u002Fai-dev-system --skill auth-nodejs-cloudbase",{"tool":58,"command":59},"pnpm","pnpm dlx skills add welflau\u002Fai-dev-system --skill auth-nodejs-cloudbase","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Fcloudbase\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-nodejs\u002FSKILL.md",true,[],[64,98,130,155,181,205],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":68,"licenseFileUrl":69,"sourceHtmlUrl":70,"categories":71,"keywords":77,"publishedAt":37},"01M6HSTDP4M3JFXEBK91VFB4PA","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Fweb-artifacts-builder\u002FSKILL.md",[72],{"categoryNo":73,"categoryName":74,"taxonomyType":75,"taxonomyTypeDesc":76},"01JBSEEDCAT000000000000009","前端开发","SCENARIO","使用场景",[78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,24,97],"web artifacts builder","web","artifacts","artifacts builder","builder","frontend","css","components","react","routing","state management","state","file","Tailwind","use","single-file","simple","ui components","multi","single",{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":68,"licenseFileUrl":102,"sourceHtmlUrl":103,"categories":104,"keywords":114,"publishedAt":37},"01M6HSDXH0JSP8R3QTNY9XZ8HN","frontend-design","Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML\u002FCSS layouts, or when styling\u002Fbeautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Ffrontend-design\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Ffrontend-design\u002FSKILL.md",[105,106,109],{"categoryNo":73,"categoryName":74,"taxonomyType":75,"taxonomyTypeDesc":76},{"categoryNo":107,"categoryName":108,"taxonomyType":75,"taxonomyTypeDesc":76},"01JBSEEDCAT000000000000015","视觉设计",{"categoryNo":110,"categoryName":111,"taxonomyType":112,"taxonomyTypeDesc":113},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[83,115,116,84,79,85,86,117,118,119,80,120,121,122,92,123,124,125,126,127,128,129],"design","frontend design","react components","create","code","examples","applications","landing","ui design","pages","aesthetics","web ui","with","generic","when",{"skillNo":131,"name":132,"nameZh":6,"description":133,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":68,"licenseFileUrl":134,"sourceHtmlUrl":135,"categories":136,"keywords":138,"publishedAt":37},"01M6HSA77QYVP7A72HREGTDN2C","algorithmic-art","Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Falgorithmic-art\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fplugins\u002Falgorithmic-art\u002FSKILL.md",[137],{"categoryNo":107,"categoryName":108,"taxonomyType":75,"taxonomyTypeDesc":76},[139,140,141,118,119,142,143,144,145,92,146,147,148,149,127,150,151,152,153,154,129],"algorithmic art","Art","algorithmic","flow","js","work","interactive","generative art","exploration","systems","users","Existing","request","generative","copyright","fields",{"skillNo":156,"name":157,"nameZh":6,"description":158,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":68,"licenseFileUrl":159,"sourceHtmlUrl":160,"categories":161,"keywords":163,"publishedAt":37},"01M6HS9HE0X390Y6RQKTY1YNGJ","theme-factory","Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors\u002Ffonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Ftheme-factory\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Ftheme-factory\u002FSKILL.md",[162],{"categoryNo":107,"categoryName":108,"taxonomyType":75,"taxonomyTypeDesc":76},[164,165,166,167,168,169,80,170,171,172,122,173,174,124,175,127,176,177,178,24,179,180],"theme factory","factory","theme","docs","toolkit","generate","SET","fly","slides","styling","artifact","themes","you","fonts","can","apply","new",{"skillNo":182,"name":183,"nameZh":6,"description":184,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":185,"categories":186,"keywords":190,"publishedAt":37},"01M6HS74GASM6FJ77F83EY679E","browsing","Use when you need direct browser control - teaches Chrome DevTools Protocol for controlling existing browser sessions, multi-tab management, form automation, and content extraction via use_browser MCP tool","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Fsuperpowers-chrome\u002Fskills\u002Fbrowsing\u002FSKILL.md",[187],{"categoryNo":188,"categoryName":189,"taxonomyType":75,"taxonomyTypeDesc":76},"01JBSEEDCAT000000000000023","Skill与智能体开发",[183,191,192,193,194,195,196,197,198,199,200,92,201,202,203,204,96,176,24,150],"MCP","automation","chrome","sessions","protocol","browser","devtools","chrome devtools","tool","direct","browser control","control","via","form",{"skillNo":206,"name":207,"nameZh":6,"description":208,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":68,"licenseFileUrl":209,"sourceHtmlUrl":210,"categories":211,"keywords":218,"publishedAt":37},"01M6HS6BZT2CKDNQ6YF20DXN4T","slack-gif-creator","Knowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like \"make me a GIF of X doing Y for Slack.\"","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Fslack-gif-creator\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fwelflau\u002Fai-dev-system\u002Fblob\u002Fmain\u002Fbackend\u002Fskills\u002Fmarketplace\u002Fcodebuddy-plugins-official\u002Fexternal_plugins\u002Fslack-gif-creator\u002FSKILL.md",[212,215],{"categoryNo":213,"categoryName":214,"taxonomyType":75,"taxonomyTypeDesc":76},"01JBSEEDCAT000000000000005","邮件与沟通",{"categoryNo":216,"categoryName":217,"taxonomyType":75,"taxonomyTypeDesc":76},"01JBSEEDCAT000000000000016","图像与多媒体",[219,220,221,222,223,224,225,226,227,92,228,149,229,230,231,24,151,129],"slack gif creator","slack","gif","creator","validation","Tools","constraints","Animation","knowledge","me","make","Utilities","concepts"]