auth-wechat-miniprogram

Implements native WeChat Mini Program authentication with CloudBase cloud functions.

Updated May 14, 2026
One-click install
npx skills add https://github.com/study-yang/Vieb-Coding-- --skill auth-wechat-miniprogram-study-yang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth-wechat-miniprogram
Source: https://github.com/study-yang/Vieb-Coding--/tree/main/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F-%E5%BF%AB%E8%AE%B0/.codebuddy/skills/auth-wechat
Command: npx skills add https://github.com/study-yang/Vieb-Coding-- --skill auth-wechat-miniprogram-study-yang

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires wx-server-sdk.

What problem does it solve? Developers building WeChat Mini Programs on CloudBase often mistakenly implement Web-style login pages or explicit token exchanges, when Mini Program identity is actually injected automatically into cloud functions. This Skill guides correct use of OPENID, UNIONID, and wx.cloud authentication behavior. ## Core Features & Use Cases - Automatic Identity Retrieval: Use cloud.getWXContext() in cloud functions to obtain verified OPENID, APPID, and UNIONID without any login API calls. - Mini Program Initialization: Configure wx.cloud.init() with the CloudBase environment ID in app.js for proper setup. - Authorization Patterns: Use OPENID for user-specific data access control and handle UNIONID availability for cross-app identification. - Use Case: A developer needs to associate database records with the calling Mini Program user; the Skill shows how to read OPENID in the cloud function and use it for per-user queries. ## Quick Start Ask the AI to show how to get the current user's OPENID in a CloudBase cloud function for a WeChat Mini Program.

Frequently Asked Questions about auth-wechat-miniprogram

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get the user OPENID in a WeChat Mini Program cloud function?

Call cloud.getWXContext() from wx-server-sdk inside the cloud function to retrieve OPENID, APPID, and UNIONID. WeChat automatically injects and verifies this identity when the Mini Program calls the function, so no login API is needed.

Do WeChat Mini Programs need an explicit login flow with CloudBase?

No, Mini Program authentication with CloudBase is native and automatic. When a user calls a cloud function via wx.cloud.callFunction, their verified identity is injected by WeChat, so Web-style login pages or token exchanges should not be built.

Why is UNIONID undefined in my cloud function?

UNIONID is only available when the Mini Program is bound to a WeChat Open Platform account and the user has authorized the Mini Program. If either condition is unmet, fall back to using OPENID, which is always present.

Can I use this approach for Web-based WeChat login?

No, this approach only covers native Mini Program identity via wx.cloud. Web-based WeChat login requires a different auth flow, and server-side Node SDK authentication outside Mini Programs is also handled separately.

How do I initialize CloudBase in a WeChat Mini Program?

Call wx.cloud.init once in app.js onLaunch with your CloudBase environment ID, optionally setting traceUser to true. In cloud functions, use cloud.init with cloud.DYNAMIC_CURRENT_ENV to target the current environment automatically.