@cloudbase/extension-wxmp-auth
v1.0.0-beta
Published
wechat miniapp auth extension for cloudbase
Downloads
3
Readme
云开发扩展插件:微信小程序登录
安装
npm install @cloudbase/extension-wxmp-auth
使用
// 引入JavaScript SDK和扩展插件
const cloudbase = require('@cloudbase/js-sdk')
const extWxmpAuth = require('@cloudbase/extension-wxmp-auth');
// 注册扩展插件
cloudbase.registerExtension(extWxmpAuth);
// 根据业务需求在合适的位置初始化Cloudbase和调用扩展功能
App({
onLaunch(){
const cloudbaseApp = tcb.init({
env: 'your-envId',
appSecret: {
// appAccessKeyId对应「移动应用安全来源」的「版本」一栏
appAccessKeyId: 'your-appAccessKeyId',
// appAccessKey对应「移动应用安全来源」的「获取凭证」一栏
appAccessKey: 'your-appAccessKey'
}
});
const auth = cloudbaseApp.auth({persistence:'local'});
// 建议登录之前先判断本地是否已有登录态
const state = await auth.getLoginState();
if(!state){
await cloudbaseApp.invokeExtension(extWxmpAuth.name);
// 登录成功
wx.showToast({
title: '登陆成功',
icon: 'success',
duration: 2000
});
}
}
});