auth-nodejs-cloudbase

0
0
Source

Complete guide for CloudBase Auth using the CloudBase Node SDK – caller identity, user lookup, custom login tickets, and server-side best practices.

Install

mkdir -p .claude/skills/auth-nodejs-cloudbase && curl -L -o skill.zip "https://mcp.directory/api/skills/download/9316" && unzip -o skill.zip -d .claude/skills/auth-nodejs-cloudbase && rm skill.zip

Installs to .claude/skills/auth-nodejs-cloudbase

About this skill

Standalone Install Note

If this environment only installed the current skill, start from the CloudBase main entry and use the published cloudbase/references/... paths for sibling skills.

  • CloudBase main entry: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/SKILL.md
  • Current skill raw source: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-nodejs/SKILL.md

Keep local references/... paths for files that ship with the current skill directory. When this file points to a sibling skill such as auth-tool or web-development, use the standalone fallback URL shown next to that reference.

Activation Contract

Use this first when

  • Node.js code in cloud functions or backend services must read caller identity, look up users, or issue custom login tickets.
  • The backend responsibility is auth / identity, not provider setup or frontend login UI.

Read before writing code if

  • The task mentions @cloudbase/node-sdk, server-side auth, custom login tickets, or "who is calling".
  • The request mixes frontend login with backend identity logic; split the flow and route client-side work elsewhere.

Then also read

  • Provider setup / publishable key -> ../auth-tool/SKILL.md (standalone fallback: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-tool/SKILL.md)
  • Web login UI that consumes custom tickets -> ../auth-web/SKILL.md (standalone fallback: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-web/SKILL.md)
  • Raw HTTP auth client -> ../http-api/SKILL.md (standalone fallback: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/http-api/SKILL.md)

Do NOT use for

  • Provider enable/disable or login console configuration.
  • Frontend login / sign-up UI.
  • Mini program native auth.

Common mistakes / gotchas

  • Using this skill as the entry point for every auth request.
  • Mixing provider-management work with Node-side identity code.
  • Reaching for raw HTTP examples when Node SDK already covers the job.

When to use this skill

Use 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:

  • CloudBase 云函数 (Node runtime) that needs to know who is calling
  • Node services that use CloudBase Node SDK to look up user information
  • Backends that issue custom login tickets for Web / mobile clients
  • Admin or ops tools that need to inspect CloudBase end-user profiles

Do NOT use this skill for:

  • Frontend Web login / sign-up flows using @cloudbase/js-sdk (handle those with the auth-web skill, not this Node skill).
  • Direct HTTP auth API integrations (this skill does not describe raw HTTP endpoints; use the http-api skill instead).
  • Database or storage operations that do not involve identity (use database/storage docs or skills).

When 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:

  • Use Web-side auth docs/skills for client login and UX.
  • Use this Node Auth skill for how the backend sees and uses the authenticated user.

How to use this skill (for a coding agent)

When you load this skill to work on a task:

  1. Clarify the runtime and responsibility

    Ask the user:

    • Where does this Node code run?
      • CloudBase 云函数
      • Long‑running Node service using CloudBase
    • What do they need from auth?
      • Just the caller identity for authorization?
      • Look up arbitrary users by UID / login identifier?
      • Bridge their own user system into CloudBase via custom login?
  2. Confirm CloudBase environment and SDK

    • Ask for:
      • env – CloudBase environment ID
    • Install the latest @cloudbase/node-sdk from npm if it is not already available.
    • Always initialize the SDK using this pattern (values can change, shape must not):
    import tcb from "@cloudbase/node-sdk";
    
    const app = tcb.init({ env: "your-env-id" });
    const auth = app.auth();
    
  3. Pick the relevant scenario from this file

    • For caller identity inside a function, use the getUserInfo scenarios.
    • For full user profile or admin lookup, use the getEndUserInfo and queryUserInfo scenarios.
    • For client systems that already have their own users, use the custom login ticket scenarios built on createTicket.
    • For logging / security, use the getClientIP scenario.
  4. Follow Node SDK API shapes exactly

    • Treat all auth.* methods and parameter shapes in this file as canonical.
    • You may change variable names and framework (e.g. Express vs 云函数 handler), but do not change SDK method names or parameter fields.
    • 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.
  5. If you are unsure about an API

    • Consult the official CloudBase Auth Node SDK documentation.
    • Only use methods and shapes that appear in the official documentation.
    • If you cannot find an API you want:
      • Prefer composing flows from the documented methods, or
      • 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.

Node auth architecture – how Node fits into CloudBase Auth

CloudBase Auth v2 separates where users log in from where backend code runs:

  • Users log in through the supported auth methods (anonymous, username/password, SMS, email, WeChat, custom login, etc.) using client SDKs or HTTP interfaces, as described in the official CloudBase Auth overview documentation.
  • Once logged in, CloudBase attaches the user identity and tokens to the environment.
  • Node code then reads that identity using the Node SDK, or bridges external identities into CloudBase using custom login.

In practice, Node code usually does one or more of:

  1. Identify the current caller

    • In 云函数, use auth.getUserInfo() to read uid, openId, and customUserId.
    • Use this identity for authorization decisions, logging, and personalisation.
  2. Look up other users

    • Use auth.getEndUserInfo(uid) when you know the CloudBase uid.
    • Use auth.queryUserInfo({ platform, platformId, uid? }) when you only have login identifiers such as phone, email, username, or a custom ID.
  3. Issue custom login tickets

    • 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.
    • 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.
  4. Log client IP for security

    • In 云函数, auth.getClientIP() returns the caller IP, which you can use for audit logs, anomaly detection, or access control.

The scenarios later in this file turn these responsibilities into explicit, copy‑pasteable patterns.


Node Auth APIs covered by this skill

This 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:

  • getUserInfo(): IGetUserInfoResult Returns { openId, appId, uid, customUserId } for the current caller.

  • getEndUserInfo(uid?: string, opts?: ICustomReqOpts): Promise<{ userInfo: EndUserInfo; requestId?: string }> Returns detailed CloudBase end‑user profile for a given uid or for the current caller (when uid is omitted).

  • queryUserInfo(query: IUserInfoQuery, opts?: ICustomReqOpts): Promise<{ userInfo: EndUserInfo; requestId?: string }> Finds a user by login identifier (platform + platformId) or uid.

  • getClientIP(): string Returns the caller’s IP address when running in a supported environment (e.g. 云函数).

  • createTicket(customUserId: string, options?: ICreateTicketOpts): string Creates a custom login ticket for the given customUserId that clients can exchange for a CloudBase login.

The 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.


Scenarios – Node auth patterns

Scenario 1: Initialize Node SDK and auth in a CloudBase function

Use this when writing a CloudBase 云函数 that needs to interact with Auth:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();

exports.main = async (event, context) => {
  // Your logic here
};

Key points:

  • Use the same env as configured for the function’s CloudBase 环境.
  • Avoid hardcoding sensitive values; prefer environment variables or function configuration.

Scenario 2: Get caller identity in a CloudBase function

Use this when you need to know who is calling your cloud function:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();

exports.main = async (event, context) => {
  const { openId, appId, uid, customUserId } = auth.getUserInfo();

  console.log("Caller identity", { openId, appId, uid, customUserId });

  // Use uid / customUserId for authorization decisions
  // e.g. check roles, permissions, or data ownership
};

Best practices:

  • Treat uid as the canonical CloudBase user identifier.
  • Use customUserId only when you have enabled 自定义登录 and mapped your own users.
  • Never trust openId/appId alone for authorization; they are WeChat‑specific identifiers.

Scenario 3: Ge


Content truncated.

miniprogram-development

TencentCloudBase

WeChat Mini Program development rules. Use this skill when developing WeChat mini programs, integrating CloudBase capabilities, and deploying mini program projects.

6221

spec-workflow

TencentCloudBase

Standard software engineering workflow for requirement analysis, technical design, and task planning. Use this skill when developing new features, complex architecture designs, multi-module integrations, or projects involving database/UI design.

857

web-development

TencentCloudBase

Web frontend project development rules. Use this skill when developing web frontend pages, deploying static hosting, and integrating CloudBase Web SDK.

95

cloudbase-document-database-in-wechat-miniprogram

TencentCloudBase

Use CloudBase document database WeChat MiniProgram SDK to query, create, update, and delete data. Supports complex queries, pagination, aggregation, and geolocation queries.

51

ai-model-nodejs

TencentCloudBase

Use this skill when developing Node.js backend services or CloudBase cloud functions (Express/Koa/NestJS, serverless, backend APIs) that need AI capabilities. Features text generation (generateText), streaming (streamText), AND image generation (generateImage) via @cloudbase/node-sdk ≥3.16.0. Built-in models include Hunyuan (hunyuan-2.0-instruct-20251111 recommended), DeepSeek (deepseek-v3.2 recommended), and hunyuan-image for images. This is the ONLY SDK that supports image generation. NOT for browser/Web apps (use ai-model-web) or WeChat Mini Program (use ai-model-wechat).

41

auth-web-cloudbase

TencentCloudBase

CloudBase Web Authentication Quick Guide - Provides concise and practical Web frontend authentication solutions with multiple login methods and complete user management.

51

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

1,4071,302

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

1,2201,024

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

9001,013

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

958658

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

970608

pdf-to-markdown

aliceisjustplaying

Convert entire PDF documents to clean, structured Markdown for full context loading. Use this skill when the user wants to extract ALL text from a PDF into context (not grep/search), when discussing or analyzing PDF content in full, when the user mentions "load the whole PDF", "bring the PDF into context", "read the entire PDF", or when partial extraction/grepping would miss important context. This is the preferred method for PDF text extraction over page-by-page or grep approaches.

1,033496

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.