auth-wechat-miniprogram

tencentcloudbase/skills · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/tencentcloudbase/skills --skill auth-wechat-miniprogram
0 commentsdiscussion
summary

WeChat Mini Program authentication with CloudBase using automatic user identity injection in cloud functions.

  • Automatic authentication: user identity (openid, appid, unionid) is seamlessly injected by WeChat when cloud functions are called, with no explicit login APIs required
  • Initialize CloudBase once in Mini Program entry point with wx.cloud.init() , then retrieve verified user context in cloud functions using cloud.getWXContext()
  • Three user identifiers available: openid (unique pe
skill.md

Activation Contract

Use this first when

  • The task is about WeChat Mini Program auth behavior, wx.cloud identity, OPENID / UNIONID, or how a mini program caller is identified in CloudBase.
  • The project is a CloudBase mini program and the auth question is about native mini program identity rather than provider configuration.

Read before writing code if

  • The request mentions mini program login, user identity in cloud functions, or wx.cloud auth assumptions.
  • The user expects a Web-style login page or explicit token exchange in a mini program; route them back to native mini program auth behavior.

Then also read

  • Mini program project implementation -> ../miniprogram-development/SKILL.md
  • Cloud function implementation -> ../cloud-functions/SKILL.md

Do NOT use for

  • Web-based WeChat login or Web auth UI.
  • Provider enable/disable or auth console setup.
  • Generic Node-side auth flows outside mini program identity handling.

Common mistakes / gotchas

  • Generating a Web-style login page for a wx.cloud mini program.
  • Treating mini program auth as a provider-configuration problem.
  • Forgetting that caller identity is injected in cloud functions automatically.

When to use this skill

Use this skill for WeChat Mini Program (小程序) authentication in a CloudBase project.

Use it when you need to:

  • Implement identity-aware WeChat Mini Program flows with CloudBase
  • Access user identity (openid, unionid) in cloud functions
  • Understand how WeChat authentication integrates with CloudBase
  • Build Mini Program features that require user identification

Key advantage: WeChat Mini Program authentication with CloudBase is seamless and automatic - no complex OAuth flows needed. When a Mini Program calls a cloud function, the user's openid is automatically injected and verified by WeChat.

Do NOT use for:

  • Web-based WeChat login (use the auth-web skill)
  • Server-side auth with Node SDK (use the auth-nodejs skill)
  • Non-WeChat authentication methods (use appropriate auth skills)

How to use this skill (for a coding agent)

  1. Confirm CloudBase environment

    • Ask the user for:
      • env – CloudBase environment ID
      • Confirm the Mini Program is linked to the CloudBase environment
  2. Understand the authentication flow

    • WeChat Mini Program authentication is native and automatic
    • No explicit login API calls needed in most cases
    • User identity is automatically available in cloud functions
    • CloudBase handles all authentication verification
  3. Pick a scenario from this file

    • For basic user identity in cloud functions, use Scenario 2
    • For Mini Program initialization, use Scenario 1
    • For calling a cloud function from the Mini Program and receiving user identity, use Scenario 3
    • For testing authentication, use Scenario 4
  4. Follow CloudBase API shapes exactly

    • Use wx-server-sdk in cloud functions
    • Use wx.cloud in Mini Program client code
    • Treat method names and parameter shapes in this file as canonical
  5. If you're unsure about an API

    • Consult the official CloudBase Mini Program documentation
    • Only use methods that appear in official documentation

Core concepts

How WeChat Mini Program authentication works with CloudBase

  1. Automatic authentication:

    • When a Mini Program user calls a cloud function, WeChat automatically injects the user's identity
    • No need for complex OAuth flows or token management
    • CloudBase verifies the authenticity of the identity
  2. User identifiers:

    • OPENID – Unique identifier for the user in this specific Mini Program
    • APPID – The Mini Program's App ID
    • UNIONID – (Optional) Unique identifier across all apps under the same WeChat Open Platform account
      • Only available when the Mini Program is bound to a WeChat Open Platform account
      • Useful for identifying the same user across multiple Mini Programs or Official Accounts
  3. Security:

    • The openid, appid, and unionid are verified and trustworthy
    • WeChat has already completed authentication
    • Developers can directly use these identifiers without additional verification
  4. No explicit login required:

    • Users are automatically authenticated when they use the Mini Program
    • No need to call login APIs in most cases
    • Identity is available immediately in cloud functions

Scenarios – WeChat Mini Program auth patterns

Scenario 1: Initialize CloudBase in Mini Program

Use this in your Mini Program's app.js or entry point:

// app.js
App({
  onLaunch: function () {
    // Initialize CloudBase
    wx.cloud.init({
      env: 'your-env-id',  // Your CloudBase environment ID
      traceUser: true      // Optional: track user access in console
    })
  }
})

Key points:

  • Call wx.cloud.init() once when the Mini Program launches
  • Set env to your CloudBase environment ID
  • traceUser: true enables user access tracking in CloudBase console (optional but recommended)

Scenario 2: Get user identity in a cloud function

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

// Cloud function: cloudfunctions/getUserInfo/index.js
const cloud = require('wx-server-sdk')

// Initialize cloud with dynamic environment
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

exports.main = async (event, context) => {
  // Get user identity - this is automatically injected by WeChat
  const { OPENID, APPID, UNIONID } = cloud.getWXContext()

  console.log('User identity:', { OPENID, APPID, UNIONID })

  // Use OPENID for user-specific operations
  // For example: query user data, check permissions, etc.

  return {
    openid: OPENID,
    appid: APPID,
    unionid: UNIONID  // May be undefined if not available
  }
}

Key points:

  • Use cloud.getWXContext() to get user identity
  • OPENID is always available and uniquely identifies the user
  • APPID identifies the Mini Program
  • UNIONID is only available when:
    • The Mini Program is bound to a WeChat Open Platform account
    • The user has authorized the Mini Program
  • These values are verified and trustworthy - no need to validate them
  • Use cloud.DYNAMIC_CURRENT_ENV to automatically use the current environment

Best practices:

  • Store OPENID in your database to associate data with users
  • Use OPENID for authorization and access control
  • Use UNIONID when you need to identify users across multiple Mini Programs or Official Accounts
  • Never expose OPENID to other users (it's a private identifier)

Scenario 3: Call cloud function from Mini Program

Use this in your Mini Program to call a cloud function and get user identity:

// In Mini Program page
Page({
  onLoad: function() {
    this.getUserInfo()
  },

  getUserInfo: function() {
    wx.cloud.callFunction({
      name: 'getUserInfo',  // Cloud function name
      data: {},             // Optional parameters
      success: res => {
        console.log('User info from cloud function:', res.result)
        // res.result contains { openid, appid, unionid }

        // Use the user info
        this.setData({
          openid: res.result.openid
        })
      },
      fail: err => {
        console.error('Failed to get user info:', err)
      }
    })
  }
})

Key points:

  • Use wx.cloud.callFunction() to call cloud functions
  • User identity is automatically passed to the cloud function
  • No need to manually send user credentials
  • Handle both success and error cases

Scenario 4: Test authentication - Simple test function

Cloud function (cloudfunctions/test/index.js):

const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

exports.main = async (event, context) => {
  // Get verified user identity - automatically injected by WeChat
  const { OPENID, APPID, UNIONID } = cloud.getWXContext()

  console.log('User identity:', { OPENID, APPID, UNIONID })

  return {
    success: true,
    message: 'Authentication successful',
    identity: {
      openid: OPENID,
      appid: APPID,
      unionid: UNIONID || 'Not available'
    },
    timestamp: new Date
how to use auth-wechat-miniprogram

How to use auth-wechat-miniprogram on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add auth-wechat-miniprogram
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/tencentcloudbase/skills --skill auth-wechat-miniprogram

The skills CLI fetches auth-wechat-miniprogram from GitHub repository tencentcloudbase/skills and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/auth-wechat-miniprogram

Reload or restart Cursor to activate auth-wechat-miniprogram. Access the skill through slash commands (e.g., /auth-wechat-miniprogram) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

User Story & Requirements Generation

Create detailed user stories, acceptance criteria, and feature specs

Example

Generate user stories for 'password reset feature' with acceptance criteria, edge cases, and test scenarios

Reduce spec writing time by 50%, ensure comprehensive coverage

Competitive Analysis

Research competitors, compare features, identify gaps

Example

Analyze 5 competitor products, create feature comparison matrix, suggest differentiation opportunities

Complete competitive research in 2 hours instead of 2 days

Roadmap Prioritization

Evaluate features using frameworks (RICE, ICE, Kano) and create prioritized backlogs

Example

Score 20 feature ideas using RICE framework, generate prioritized roadmap with rationale

Make data-driven prioritization decisions faster

Stakeholder Communication

Draft PRDs, status updates, and stakeholder presentations

Example

Create executive summary of Q3 roadmap, monthly progress report, feature launch announcement

Save 3-5 hours/week on communication overhead

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client
  • Access to product documentation and roadmap tools (Jira, Notion, etc.)
  • Understanding of product management frameworks (RICE, Jobs-to-be-Done, etc.)
  • Stakeholder contact information and communication channels

Time Estimate

30-60 minutes to see productivity improvements

Installation Steps

  1. 1.Install product management skill
  2. 2.Start with user story generation for known feature
  3. 3.Progress to competitive analysis: research 2-3 competitors
  4. 4.Use for roadmap prioritization: apply RICE/ICE scoring
  5. 5.Draft stakeholder communications and refine based on feedback
  6. 6.Build template library for recurring PM tasks
  7. 7.Share effective prompts with product team

Common Pitfalls

  • Not validating competitive research—verify facts before sharing
  • Accepting user stories without involving engineering team
  • Over-relying on frameworks without qualitative judgment
  • Not customizing outputs to company culture and communication style
  • Skipping stakeholder validation of generated requirements

Best Practices

✓ Do

  • +Validate research and competitive analysis with real data
  • +Collaborate with engineering when generating technical requirements
  • +Customize frameworks and templates to your company context
  • +Use skill for first drafts, refine with stakeholder input
  • +Document successful prompt patterns for PM tasks
  • +Combine AI efficiency with human judgment and intuition

✗ Don't

  • Don't publish competitive analysis without fact-checking
  • Don't finalize user stories without engineering review
  • Don't make prioritization decisions solely on AI scoring
  • Don't skip customer validation of generated requirements
  • Don't ignore company-specific context and culture

💡 Pro Tips

  • Provide context: company goals, constraints, customer feedback
  • Ask for alternatives: 'Show 3 ways to prioritize this roadmap'
  • Request stakeholder-specific formatting: 'Executive summary vs. engineering spec'
  • Use skill for 70% generation + 30% customization to company needs

When to Use This

✓ Use When

Use for user story writing, competitive research, roadmap prioritization, stakeholder communication, and PRD drafting. Best for reducing repetitive documentation and research work.

✗ Avoid When

Avoid for strategic product vision (requires deep customer empathy), pricing decisions (needs market and financial expertise), or when face-to-face customer discovery is more valuable than speed.

Learning Path

  1. 1Basic: user stories, feature specs, status updates
  2. 2Intermediate: competitive analysis, prioritization frameworks, PRDs
  3. 3Advanced: product strategy, go-to-market planning, OKR setting
  4. 4Expert: product vision, market positioning, business model innovation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.759 reviews
  • Pratham Ware· Dec 12, 2024

    auth-wechat-miniprogram has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Dhruvi Jain· Dec 8, 2024

    Registry listing for auth-wechat-miniprogram matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Isabella Anderson· Dec 8, 2024

    We added auth-wechat-miniprogram from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Yusuf Rao· Dec 4, 2024

    auth-wechat-miniprogram fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Neel Desai· Dec 4, 2024

    Useful defaults in auth-wechat-miniprogram — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Sakura Ndlovu· Dec 4, 2024

    auth-wechat-miniprogram reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Oshnikdeep· Nov 27, 2024

    auth-wechat-miniprogram reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Isabella Zhang· Nov 27, 2024

    auth-wechat-miniprogram fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Yusuf Srinivasan· Nov 23, 2024

    We added auth-wechat-miniprogram from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Ren Jackson· Nov 23, 2024

    Registry listing for auth-wechat-miniprogram matched our evaluation — installs cleanly and behaves as described in the markdown.

showing 1-10 of 59

1 / 6