[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CQA9MEJG8RASHSXNE3D3WZ":3,"skill-same:01M7CQA9MEJG8RASHSXNE3D3WZ":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},"01M7CQA9MEJG8RASHSXNE3D3WZ","auth-wechat-miniprogram",null,"Complete guide for WeChat Mini Program authentication with CloudBase - native login, user identity, and cloud function integration.","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-Skills-技能包\u002FYYC3-Skills-技能包-code-skills\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-wechat\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: auth-wechat-miniprogram\ndescription: Complete guide for WeChat Mini Program authentication with CloudBase - native login, user identity, and cloud function integration.\nalwaysApply: false\n---\n\n## When to use this skill\n\nUse this skill for **WeChat Mini Program (小程序) authentication** in a CloudBase project.\n\nUse it when you need to:\n\n- Implement WeChat Mini Program login with CloudBase\n- Access user identity (openid, unionid) in cloud functions\n- Understand how WeChat authentication integrates with CloudBase\n- Build Mini Program features that require user identification\n\n**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.\n\n**Do NOT use for:**\n\n- Web-based WeChat login (use the **auth-web** skill)\n- Server-side auth with Node SDK (use the **auth-nodejs** skill)\n- Non-WeChat authentication methods (use appropriate auth skills)\n\n---\n\n## How to use this skill (for a coding agent)\n\n1. **Confirm CloudBase environment**\n   - Ask the user for:\n     - `env` – CloudBase environment ID\n     - Confirm the Mini Program is linked to the CloudBase environment\n\n2. **Understand the authentication flow**\n   - WeChat Mini Program authentication is **native and automatic**\n   - No explicit login API calls needed in most cases\n   - User identity is automatically available in cloud functions\n   - CloudBase handles all authentication verification\n\n3. **Pick a scenario from this file**\n   - For basic user identity in cloud functions, use **Scenario 2**\n   - For Mini Program initialization, use **Scenario 1**\n   - For calling a cloud function from the Mini Program and receiving user identity, use **Scenario 3**\n   - For testing authentication, use **Scenario 4**\n\n4. **Follow CloudBase API shapes exactly**\n   - Use `wx-server-sdk` in cloud functions\n   - Use `wx.cloud` in Mini Program client code\n   - Treat method names and parameter shapes in this file as canonical\n\n5. **If you're unsure about an API**\n   - Consult the official CloudBase Mini Program documentation\n   - Only use methods that appear in official documentation\n\n---\n\n## Core concepts\n\n### How WeChat Mini Program authentication works with CloudBase\n\n1. **Automatic authentication:**\n   - When a Mini Program user calls a cloud function, WeChat automatically injects the user's identity\n   - No need for complex OAuth flows or token management\n   - CloudBase verifies the authenticity of the identity\n\n2. **User identifiers:**\n   - `OPENID` – Unique identifier for the user in this specific Mini Program\n   - `APPID` – The Mini Program's App ID\n   - `UNIONID` – (Optional) Unique identifier across all apps under the same WeChat Open Platform account\n     - Only available when the Mini Program is bound to a WeChat Open Platform account\n     - Useful for identifying the same user across multiple Mini Programs or Official Accounts\n\n3. **Security:**\n   - The `openid`, `appid`, and `unionid` are **verified and trustworthy**\n   - WeChat has already completed authentication\n   - Developers can directly use these identifiers without additional verification\n\n4. **No explicit login required:**\n   - Users are automatically authenticated when they use the Mini Program\n   - No need to call login APIs in most cases\n   - Identity is available immediately in cloud functions\n\n---\n\n## Scenarios – WeChat Mini Program auth patterns\n\n### Scenario 1: Initialize CloudBase in Mini Program\n\nUse this in your Mini Program's `app.js` or entry point:\n\n```js\n\u002F\u002F app.js\nApp({\n  onLaunch: function () {\n    \u002F\u002F Initialize CloudBase\n    wx.cloud.init({\n      env: 'your-env-id',  \u002F\u002F Your CloudBase environment ID\n      traceUser: true      \u002F\u002F Optional: track user access in console\n    })\n  }\n})\n```\n\n**Key points:**\n\n- Call `wx.cloud.init()` once when the Mini Program launches\n- Set `env` to your CloudBase environment ID\n- `traceUser: true` enables user access tracking in CloudBase console (optional but recommended)\n\n---\n\n### Scenario 2: Get user identity in a cloud function\n\nUse this when you need to know **who is calling** your cloud function:\n\n```js\n\u002F\u002F Cloud function: cloudfunctions\u002FgetUserInfo\u002Findex.js\nconst cloud = require('wx-server-sdk')\n\n\u002F\u002F Initialize cloud with dynamic environment\ncloud.init({\n  env: cloud.DYNAMIC_CURRENT_ENV\n})\n\nexports.main = async (event, context) => {\n  \u002F\u002F Get user identity - this is automatically injected by WeChat\n  const { OPENID, APPID, UNIONID } = cloud.getWXContext()\n\n  console.log('User identity:', { OPENID, APPID, UNIONID })\n\n  \u002F\u002F Use OPENID for user-specific operations\n  \u002F\u002F For example: query user data, check permissions, etc.\n\n  return {\n    openid: OPENID,\n    appid: APPID,\n    unionid: UNIONID  \u002F\u002F May be undefined if not available\n  }\n}\n```\n\n**Key points:**\n\n- Use `cloud.getWXContext()` to get user identity\n- `OPENID` is always available and uniquely identifies the user\n- `APPID` identifies the Mini Program\n- `UNIONID` is only available when:\n  - The Mini Program is bound to a WeChat Open Platform account\n  - The user has authorized the Mini Program\n- These values are **verified and trustworthy** - no need to validate them\n- Use `cloud.DYNAMIC_CURRENT_ENV` to automatically use the current environment\n\n**Best practices:**\n\n- Store `OPENID` in your database to associate data with users\n- Use `OPENID` for authorization and access control\n- Use `UNIONID` when you need to identify users across multiple Mini Programs or Official Accounts\n- Never expose `OPENID` to other users (it's a private identifier)\n\n---\n\n### Scenario 3: Call cloud function from Mini Program\n\nUse this in your Mini Program to call a cloud function and get user identity:\n\n```js\n\u002F\u002F In Mini Program page\nPage({\n  onLoad: function() {\n    this.getUserInfo()\n  },\n\n  getUserInfo: function() {\n    wx.cloud.callFunction({\n      name: 'getUserInfo',  \u002F\u002F Cloud function name\n      data: {},             \u002F\u002F Optional parameters\n      success: res => {\n        console.log('User info from cloud function:', res.result)\n        \u002F\u002F res.result contains { openid, appid, unionid }\n\n        \u002F\u002F Use the user info\n        this.setData({\n          openid: res.result.openid\n        })\n      },\n      fail: err => {\n        console.error('Failed to get user info:', err)\n      }\n    })\n  }\n})\n```\n\n**Key points:**\n\n- Use `wx.cloud.callFunction()` to call cloud functions\n- User identity is automatically passed to the cloud function\n- No need to manually send user credentials\n- Handle both success and error cases\n\n---\n\n### Scenario 4: Test authentication - Simple test function\n\n**Cloud function (cloudfunctions\u002Ftest\u002Findex.js):**\n\n```js\nconst cloud = require('wx-server-sdk')\n\ncloud.init({\n  env: cloud.DYNAMIC_CURRENT_ENV\n})\n\nexports.main = async (event, context) => {\n  \u002F\u002F Get verified user identity - automatically injected by WeChat\n  const { OPENID, APPID, UNIONID } = cloud.getWXContext()\n\n  console.log('User identity:', { OPENID, APPID, UNIONID })\n\n  return {\n    success: true,\n    message: 'Authentication successful',\n    identity: {\n      openid: OPENID,\n      appid: APPID,\n      unionid: UNIONID || 'Not available'\n    },\n    timestamp: new Date().toISOString()\n  }\n}\n```\n\n**Mini Program code:**\n\n```js\n\u002F\u002F pages\u002Findex\u002Findex.js\nPage({\n  data: {\n    userIdentity: null\n  },\n\n  onLoad: function() {\n    this.testAuth()\n  },\n\n  testAuth: function() {\n    console.log('Testing authentication...')\n\n    wx.cloud.callFunction({\n      name: 'test',\n      success: res => {\n        console.log('Authentication test result:', res.result)\n\n        this.setData({\n          userIdentity: res.result.identity\n        })\n\n        wx.showToast({\n          title: 'Auth successful',\n          icon: 'success'\n        })\n      },\n      fail: err => {\n        console.error('Authentication test failed:', err)\n        wx.showToast({\n          title: 'Auth failed',\n          icon: 'error'\n        })\n      }\n    })\n  }\n})\n```\n\n**Key points:**\n\n- No explicit login API call needed\n- User identity is automatically available in cloud function\n- `OPENID` is always present and verified\n- `UNIONID` may be undefined if not available\n- Use this pattern to verify authentication is working correctly\n\n---\n\n## Best practices\n\n### 1. Always use cloud.DYNAMIC_CURRENT_ENV\n\n```js\ncloud.init({\n  env: cloud.DYNAMIC_CURRENT_ENV\n})\n```\n\nThis ensures the cloud function uses the correct environment automatically.\n\n### 2. Store OPENID for user identification\n\n- Use `OPENID` as the primary user identifier\n- Store it in your database to associate data with users\n- Never expose `OPENID` to other users\n\n### 3. Handle UNIONID availability\n\n```js\nconst { OPENID, UNIONID } = cloud.getWXContext()\n\nif (UNIONID) {\n  \u002F\u002F User has UNIONID - can be used for cross-app identification\n  console.log('UNIONID available:', UNIONID)\n} else {\n  \u002F\u002F UNIONID not available - use OPENID only\n  console.log('Using OPENID only:', OPENID)\n}\n```\n\n### 4. Use OPENID for user-specific operations\n\n- Use `OPENID` to identify and authorize users\n- Store `OPENID` when you need to associate data with users\n- Use `OPENID` in queries to ensure users only access their own data\n\n### 5. Error handling\n\nAlways handle errors when calling cloud functions:\n\n```js\nwx.cloud.callFunction({\n  name: 'myFunction',\n  success: res => {\n    \u002F\u002F Handle success\n  },\n  fail: err => {\n    console.error('Cloud function error:', err)\n    \u002F\u002F Show user-friendly error message\n    wx.showToast({\n      title: 'Operation failed',\n      icon: 'error'\n    })\n  }\n})\n```\n\n### 6. Initialize CloudBase early\n\nInitialize CloudBase in `app.js` `onLaunch`:\n\n```js\nApp({\n  onLaunch: function () {\n    wx.cloud.init({\n      env: 'your-env-id',\n      traceUser: true\n    })\n  }\n})\n```\n\n---\n\n## Common patterns\n\n### Pattern 1: Get and return user identity\n\n```js\nconst cloud = require('wx-server-sdk')\ncloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })\n\nexports.main = async (event, context) => {\n  const { OPENID, APPID, UNIONID } = cloud.getWXContext()\n\n  return {\n    openid: OPENID,\n    appid: APPID,\n    unionid: UNIONID || null\n  }\n}\n```\n\n### Pattern 2: Use OPENID for authorization\n\n```js\nconst cloud = require('wx-server-sdk')\ncloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })\n\nexports.main = async (event, context) => {\n  const { OPENID } = cloud.getWXContext()\n\n  \u002F\u002F Check if user is authorized\n  if (OPENID === event.resourceOwnerId) {\n    \u002F\u002F User is authorized to access this resource\n    return { authorized: true }\n  } else {\n    return { authorized: false, error: 'Unauthorized' }\n  }\n}\n```\n\n### Pattern 3: Handle UNIONID availability\n\n```js\nconst cloud = require('wx-server-sdk')\ncloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })\n\nexports.main = async (event, context) => {\n  const { OPENID, UNIONID } = cloud.getWXContext()\n\n  if (UNIONID) {\n    \u002F\u002F Can use UNIONID for cross-app user identification\n    console.log('User has UNIONID:', UNIONID)\n  } else {\n    \u002F\u002F Fall back to OPENID only\n    console.log('Using OPENID only:', OPENID)\n  }\n\n  return { openid: OPENID, hasUnionId: !!UNIONID }\n}\n```\n\n---\n\n## Summary\n\nWeChat Mini Program authentication with CloudBase is **simple and secure**:\n\n1. **No explicit login needed** - authentication is automatic\n2. **User identity is verified** - `OPENID`, `APPID`, and `UNIONID` are trustworthy\n3. **Easy to use** - just call `cloud.getWXContext()` in cloud functions\n4. **Secure by default** - WeChat handles all authentication verification\n\n**Key takeaways:**\n\n- Initialize CloudBase with `wx.cloud.init()` in Mini Program\n- Use `cloud.getWXContext()` to get user identity in cloud functions\n- Use `OPENID` for user identification and authorization\n- Handle `UNIONID` availability appropriately\n- No explicit login API calls needed - authentication is automatic\n\nFor more complex authentication scenarios or integration with other systems, consider using CloudBase custom login in combination with WeChat authentication.\n","## When to use this skill\n\nUse this skill for **WeChat Mini Program (小程序) authentication** in a CloudBase project.\n\nUse it when you need to:\n\n- Implement WeChat Mini Program login with CloudBase\n- Access user identity (openid, unionid) in cloud functions\n- Understand how WeChat authentication integrates with CloudBase\n- Build Mini Program features that require user identification\n\n**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.\n\n**Do NOT use for:**\n\n- Web-based WeChat login (use the **auth-web** skill)\n- Server-side auth with Node SDK (use the **auth-nodejs** skill)\n- Non-WeChat authentication methods (use appropriate auth skills)\n\n---\n\n## How to use this skill (for a coding agent)\n\n1. **Confirm CloudBase environment**\n   - Ask the user for:\n     - `env` – CloudBase environment ID\n     - Confirm the Mini Program is linked to the CloudBase environment\n\n2. **Understand the authentication flow**\n   - WeChat Mini Program authentication is **native and automatic**\n   - No explicit login API calls needed in most cases\n   - User identity is automatically available in cloud functions\n   - CloudBase handles all authentication verification\n\n3. **Pick a scenario from this file**\n   - For basic user identity in cloud functions, use **Scenario 2**\n   - For Mini Program initialization, use **Scenario 1**\n   - For calling a cloud function from the Mini Program and receiving user identity, use **Scenario 3**\n   - For testing authentication, use **Scenario 4**\n\n4. **Follow CloudBase API shapes exactly**\n   - Use `wx-server-sdk` in cloud functions\n   - Use `wx.cloud` in Mini Program client code\n   - Treat method names and parameter shapes in this file as canonical\n\n5. **If you're unsure about an API**\n   - Consult the official CloudBase Mini Program documentation\n   - Only use methods that appear in official documentation\n\n---\n\n## Core concepts\n\n### How WeChat Mini Program authentication works with CloudBase\n\n1. **Automatic authentication:**\n   - When a Mini Program user calls a cloud function, WeChat automatically injects the user's identity\n   - No need for complex OAuth flows or token management\n   - CloudBase verifies the authenticity of the identity\n\n2. **User identifiers:**\n   - `OPENID` – Unique identifier for the user in this specific Mini Program\n   - `APPID` – The Mini Program's App ID\n   - `UNIONID` – (Optional) Unique identifier across all apps under the same WeChat Open Platform account\n     - Only available when the Mini Program is bound to a WeChat Open Platform account\n     - Useful for identifying the same user across multiple Mini Programs or Official Accounts\n\n3. **Security:**\n   - The `openid`, `appid`, and `unionid` are **verified and trustworthy**\n   - WeChat has already completed authentication\n   - Developers can directly use these identifiers without additional verification\n\n4. **No explicit login required:**\n   - Users are automatically authenticated when they use the Mini Program\n   - No need to call login APIs in most cases\n   - Identity is available immediately in cloud functions\n\n---\n\n## Scenarios – WeChat Mini Program auth patterns\n\n### Scenario 1: Initialize CloudBase in Mini Program\n\nUse this in your Mini Program's `app.js` or entry point:\n\n```js\n\u002F\u002F app.js\nApp({\n  onLaunch: function () {\n    \u002F\u002F Initialize CloudBase\n    wx.cloud.init({\n      env: 'your-env-id',  \u002F\u002F Your CloudBase environment ID\n      traceUser: true      \u002F\u002F Optional: track user access in console\n    })\n  }\n})\n```\n\n**Key points:**\n\n- Call `wx.cloud.init()` once when the Mini Program launches\n- Set `env` to your CloudBase environment ID\n- `traceUser: true` enables user access tracking in CloudBase console (optional but recommended)\n\n---\n\n### Scenario 2: Get user identity in a cloud function\n\nUse this when you need to know **who is calling** your cloud function:\n\n```js\n\u002F\u002F Cloud function: cloudfunctions\u002FgetUserInfo\u002Findex.js\nconst cloud = require('wx-server-sdk')\n\n\u002F\u002F Initialize cloud with dynamic environment\ncloud.init({\n  env: cloud.DYNAMIC_CURRENT_ENV\n})\n\nexports.main = async (event, context) => {\n  \u002F\u002F Get user identity - this is automatically injected by WeChat\n  const { OPENID, APPID, UNIONID } = cloud.getWXContext()\n\n  console.log('User identity:', { OPENID, APPID, UNIONID })\n\n  \u002F\u002F Use OPENID for user-specific operations\n  \u002F\u002F For example: query user data, check permissions, etc.\n\n  return {\n    openid: OPENID,\n    appid: APPID,\n    unionid: UNIONID  \u002F\u002F May be undefined if not available\n  }\n}\n```\n\n**Key points:**\n\n- Use `cloud.getWXContext()` to get user identity\n- `OPENID` is always available and uniquely identifies the user\n- `APPID` identifies the Mini Program\n- `UNIONID` is only available when:\n  - The Mini Program is bound to a WeChat Open Platform account\n  - The user has authorized the Mini Program\n- These values are **verified and trustworthy** - no need to validate them\n- Use `cloud.DYNAMIC_CURRENT_ENV` to automatically use the current environment\n\n**Best practices:**\n\n- Store `OPENID` in your database to associate data with users\n- Use `OPENID` for authorization and access control\n- Use `UNIONID` when you need to identify users across multiple Mini Programs or Official Accounts\n- Never expose `OPENID` to other users (it's a private identifier)\n\n---\n\n### Scenario 3: Call cloud function from Mini Program\n\nUse this in your Mini Program to call a cloud function and get user identity:\n\n```js\n\u002F\u002F In Mini Program page\nPage({\n  onLoad: function() {\n    this.getUserInfo()\n  },\n\n  getUserInfo: function() {\n    wx.cloud.callFunction({\n      name: 'getUserInfo',  \u002F\u002F Cloud function name\n      data: {},             \u002F\u002F Optional parameters\n      success: res => {\n        console.log('User info from cloud function:', res.result)\n        \u002F\u002F res.result contains { openid, appid, unionid }\n\n        \u002F\u002F Use the user info\n        this.setData({\n          openid: res.result.openid\n        })\n      },\n      fail: err => {\n        console.error('Failed to get user info:', err)\n      }\n    })\n  }\n})\n```\n\n**Key points:**\n\n- Use `wx.cloud.callFunction()` to call cloud functions\n- User identity is automatically passed to the cloud function\n- No need to manually send user credentials\n- Handle both success and error cases\n\n---\n\n### Scenario 4: Test authentication - Simple test function\n\n**Cloud function (cloudfunctions\u002Ftest\u002Findex.js):**\n\n```js\nconst cloud = require('wx-server-sdk')\n\ncloud.init({\n  env: cloud.DYNAMIC_CURRENT_ENV\n})\n\nexports.main = async (event, context) => {\n  \u002F\u002F Get verified user identity - automatically injected by WeChat\n  const { OPENID, APPID, UNIONID } = cloud.getWXContext()\n\n  console.log('User identity:', { OPENID, APPID, UNIONID })\n\n  return {\n    success: true,\n    message: 'Authentication successful',\n    identity: {\n      openid: OPENID,\n      appid: APPID,\n      unionid: UNIONID || 'Not available'\n    },\n    timestamp: new Date().toISOString()\n  }\n}\n```\n\n**Mini Program code:**\n\n```js\n\u002F\u002F pages\u002Findex\u002Findex.js\nPage({\n  data: {\n    userIdentity: null\n  },\n\n  onLoad: function() {\n    this.testAuth()\n  },\n\n  testAuth: function() {\n    console.log('Testing authentication...')\n\n    wx.cloud.callFunction({\n      name: 'test',\n      success: res => {\n        console.log('Authentication test result:', res.result)\n\n        this.setData({\n          userIdentity: res.result.identity\n        })\n\n        wx.showToast({\n          title: 'Auth successful',\n          icon: 'success'\n        })\n      },\n      fail: err => {\n        console.error('Authentication test failed:', err)\n        wx.showToast({\n          title: 'Auth failed',\n          icon: 'error'\n        })\n      }\n    })\n  }\n})\n```\n\n**Key points:**\n\n- No explicit login API call needed\n- User identity is automatically available in cloud function\n- `OPENID` is always present and verified\n- `UNIONID` may be undefined if not available\n- Use this pattern to verify authentication is working correctly\n\n---\n\n## Best practices\n\n### 1. Always use cloud.DYNAMIC_CURRENT_ENV\n\n```js\ncloud.init({\n  env: cloud.DYNAMIC_CURRENT_ENV\n})\n```\n\nThis ensures the cloud function uses the correct environment automatically.\n\n### 2. Store OPENID for user identification\n\n- Use `OPENID` as the primary user identifier\n- Store it in your database to associate data with users\n- Never expose `OPENID` to other users\n\n### 3. Handle UNIONID availability\n\n```js\nconst { OPENID, UNIONID } = cloud.getWXContext()\n\nif (UNIONID) {\n  \u002F\u002F User has UNIONID - can be used for cross-app identification\n  console.log('UNIONID available:', UNIONID)\n} else {\n  \u002F\u002F UNIONID not available - use OPENID only\n  console.log('Using OPENID only:', OPENID)\n}\n```\n\n### 4. Use OPENID for user-specific operations\n\n- Use `OPENID` to identify and authorize users\n- Store `OPENID` when you need to associate data with users\n- Use `OPENID` in queries to ensure users only access their own data\n\n### 5. Error handling\n\nAlways handle errors when calling cloud functions:\n\n```js\nwx.cloud.callFunction({\n  name: 'myFunction',\n  success: res => {\n    \u002F\u002F Handle success\n  },\n  fail: err => {\n    console.error('Cloud function error:', err)\n    \u002F\u002F Show user-friendly error message\n    wx.showToast({\n      title: 'Operation failed',\n      icon: 'error'\n    })\n  }\n})\n```\n\n### 6. Initialize CloudBase early\n\nInitialize CloudBase in `app.js` `onLaunch`:\n\n```js\nApp({\n  onLaunch: function () {\n    wx.cloud.init({\n      env: 'your-env-id',\n      traceUser: true\n    })\n  }\n})\n```\n\n---\n\n## Common patterns\n\n### Pattern 1: Get and return user identity\n\n```js\nconst cloud = require('wx-server-sdk')\ncloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })\n\nexports.main = async (event, context) => {\n  const { OPENID, APPID, UNIONID } = cloud.getWXContext()\n\n  return {\n    openid: OPENID,\n    appid: APPID,\n    unionid: UNIONID || null\n  }\n}\n```\n\n### Pattern 2: Use OPENID for authorization\n\n```js\nconst cloud = require('wx-server-sdk')\ncloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })\n\nexports.main = async (event, context) => {\n  const { OPENID } = cloud.getWXContext()\n\n  \u002F\u002F Check if user is authorized\n  if (OPENID === event.resourceOwnerId) {\n    \u002F\u002F User is authorized to access this resource\n    return { authorized: true }\n  } else {\n    return { authorized: false, error: 'Unauthorized' }\n  }\n}\n```\n\n### Pattern 3: Handle UNIONID availability\n\n```js\nconst cloud = require('wx-server-sdk')\ncloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })\n\nexports.main = async (event, context) => {\n  const { OPENID, UNIONID } = cloud.getWXContext()\n\n  if (UNIONID) {\n    \u002F\u002F Can use UNIONID for cross-app user identification\n    console.log('User has UNIONID:', UNIONID)\n  } else {\n    \u002F\u002F Fall back to OPENID only\n    console.log('Using OPENID only:', OPENID)\n  }\n\n  return { openid: OPENID, hasUnionId: !!UNIONID }\n}\n```\n\n---\n\n## Summary\n\nWeChat Mini Program authentication with CloudBase is **simple and secure**:\n\n1. **No explicit login needed** - authentication is automatic\n2. **User identity is verified** - `OPENID`, `APPID`, and `UNIONID` are trustworthy\n3. **Easy to use** - just call `cloud.getWXContext()` in cloud functions\n4. **Secure by default** - WeChat handles all authentication verification\n\n**Key takeaways:**\n\n- Initialize CloudBase with `wx.cloud.init()` in Mini Program\n- Use `cloud.getWXContext()` to get user identity in cloud functions\n- Use `OPENID` for user identification and authorization\n- Handle `UNIONID` availability appropriately\n- No explicit login API calls needed - authentication is automatic\n\nFor more complex authentication scenarios or integration with other systems, consider using CloudBase custom login in combination with WeChat authentication.\n",{"name":5,"alwaysApply":20,"description":7},"main","87afe6ce96220accf50a345dea46784c8c9f210e","YYC3-Skills-技能包\u002FYYC3-Skills-技能包-code-skills\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-wechat",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-wechat-miniprogram",{"tool":39,"command":40},"bunx","bunx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill auth-wechat-miniprogram",{"tool":42,"command":43},"pnpm","pnpm dlx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill auth-wechat-miniprogram","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Skills-技能包\u002FYYC3-Skills-技能包-code-skills\u002Fskills\u002Fcloudbase\u002Freferences\u002Fauth-wechat\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",[],[]]